Saturday, July 25, 2009

Browser Caching -Expires,Cache Control & Deflate

Expires Header – will stop the request(304 request-if modified ?) sent from browser

Disadvantage – even if the asset changes the browser will serverthe cached image without even checking if the image has changed.

The only solution is to come up with Versoning if we set Expires.

Syntax(in apache httpd.conf)

#Adding expires header

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">

Header set Expires "Wed, 31 Dec 2008 23:59:59 GMT"


Also can set using access plus x days

Cache control will over ride expires header even if set.

Add this line for disabling cache control

Header set Cache-control: No-cache,no-store

Add this line for enabling cache control

Header set Cache-Control "private,max-age=0,must-revalidate"

The following lines can be used to remove the ETag header

Header unset ETag

FileETag None

Etag generates the tag using the ip of the hosted machine and when the assets are hosted in multiple machines , and requests may go to different machines and hence e-tags may be different and they will be downloaded again

Also while doing scp(having multiple deployment machines), to retain the original timestamps we need to use ‘scp –p’ whereas the touch command can change the access/modified time for the file after it is copied.

The above cache control works on the basis of the last modified time .And hence the modified time stamps have to be kept same in all the asset holding machines , so when copying the assets copy with same time stamps else requests will be sent again.

Adding Gzip configuration
<FilesMatch "\.(html|htm|js|css)$">
SetOutputFilter DEFLATE

Adding Expires
ExpiresActive On
ExpiresDefault "now plus 0 seconds"

<FilesMatch "\.(jpg|jpeg|png|gif|swf|mp3)$">
ExpiresByType image/jpg "access plus 14 days"
ExpiresByType image/jpeg "access plus 14 days"
Header set Cache-Control "public,max-age=1209600"
Header unset Pragma

Apache HttpClient

Although the package provides basic functionality for accessing resources via HTTP, it doesn't provide the
full flexibility or functionality needed by many applications. The Jakarta Commons HttpClient component seeks to fill
this void by providing an efficient, up-to-date, and feature-rich package implementing the client side of the most
recent HTTP standards and recommendations

Feature List

CGLIB-For Dynamic Proxies

The Spring Framework implements method injection by dynamically generating a subclass overriding the method, using bytecode generation via the CGLIB library.

Please be aware that in order for this dynamic subclassing to work, you will need to have the CGLIB jar(s) on your classpath. Additionally, the class that the Spring container is going to subclass cannot be final, and the method that is being overridden cannot be final either.

By default, when the Spring container is creating a proxy for a bean that is marked up with the <aop:scoped-proxy/> element, a CGLIB-based class proxy will be created. This means that you need to have the CGLIB library on the classpath of your application.

Note: CGLIB proxies will only intercept public method calls! Do not call non-public methods on such a proxy; they will not be delegated to the scoped target object.

You can choose to have the Spring container create 'standard' JDK interface-based proxies for such scoped beans by specifying 'false' for the value of the 'proxy-target-class' attribute of the <aop:scoped-proxy/> element. Using JDK interface-based proxies does mean that you don't need any additional libraries on your application's classpath to effect such proxying, but it does mean that the class of the scoped bean must implement at least one interface, and all of the collaborators into which the scoped bean is injected must be referencing the bean via one of its interfaces.

Spring AOP can also use CGLIB proxies. This is necessary to proxy classes, rather than interfaces. CGLIB is used by default if a business object does not implement an interface. As it is good practice to program to interfaces rather than classes, business classes normally will implement one or more business interfaces. It is possible to force the use of CGLIB, in those (hopefully rare) cases where you need to advise a method that is not declared on an interface, or where you need to pass a proxied object to a method as a concrete type.

Free Domain Names @!