Hi,
After digging deep into the sites and configuring my apache server ( after so many failures )
Here i came up with list of things to be done for
- Gziping the CSS/JS, image and flash files
- Removing Etags from CSS/JS and Image/flash files.
- Adding expires header to CSS/JS and image/flash files.
First, Go to your apache’s httpd.conf file
I my case its “C:\xampp\apache\conf\httpd.conf”
The lines beginning with # indicate that these are comments
Remove the comments for these below mentioned lines
LoadModule deflate_module modules/mod_deflate.so LoadModule expires_module modules/mod_expires.so LoadModule headers_module modules/mod_headers.so
Add the below thing to remove the ETags. This can be added at the end
FileETag None
To Add expires header to all the files that are requested from the server
ExpiresActive On ExpiresDefault "access plus 300 seconds" <Directory "/myProject/webResources"> Options FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all ExpiresByType text/html "access plus 1 day" ExpiresByType text/css "access plus 1 day" ExpiresByType text/javascript "access plus 1 day" ExpiresByType image/gif "access plus 1 day" ExpiresByType image/jpg "access plus 1 day" ExpiresByType image/png "access plus 1 day" ExpiresByType application/x-shockwave-flash "access plus 1 day" </Directory>
Note: Here “myProject” is the folder where my web pages are present. i.e “C:\xampp\htdocs\myProject”. Where “webResources” is the directory where my css, js, image, flash files are present. For all these files I am adding expires header of one day. Means these files can be can be cached for the entire day in the local browser. In other words these files are not changed at least for one day.
To Gzip the CSS and JS files that are present in the “webResources” folder
<Location "/sprintCommunity/webResources"> # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 # the above regex won't work. You can use the following # workaround to get the desired effect: BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </Location>
Please post a comment if this was useful to you. Thanks
Awsome post and will be really helpful for everyone who wanna enhance thier site performance. sridhar u rocked buddy.
Really helpful info,
Thank for helping
The gzip part worked on my server but the expires headers did not. Hopefully another website can help me figure out the reason why. Thanks.
Nice post. Really help full
But google page speed suggests that a 30day expiry time is good practice.
The gzip compression didnt work on my server, not sure why.
I don’t think I’ve seen this said that way before. You actually have cleared this up for me. Thanks!
Hey,
can you tell me why did you set ETags to none?
Yslow is always saying to me to configure ETags
Cheers…
Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser’s cache matches the one on the origin server. The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won’t match when a browser gets the original component from one server and later tries to validate that component on a different server—a situation that is all too common on web sites that use a cluster of servers to handle requests.
As we use expires header (more info above in the original blog) we can avoid this over head. Thus loading resources from the server faster without doing the ETag check.
Very good post.It is very useful for me.But In last part of code what is “/sprintCommunity/”. Please let me know.
1.We currently have static file caching for Apache headers.However its not perfect.
2.We need to work on a solution involving Etags header (like a checksum) to ensure the webserver realizes a new version is available and then forces a file refresh.
3.So that even if browser initiates a request, server knows whether to really send the file back or not based on the ETag.
Please suggest me any solution on this at the earliest.
Thanks in advance.
you can do this by setting the expire header
ExpiresDefault "access plus 30 minutes"
Also don’t forget to enable this ExpiresActive
# enable expirations
ExpiresActive On
# enable expirations
ExpiresActive On
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
ExpiresDefault A300
ExpiresDefault “access plus 30 minutes”
ExpiresDefault “access plus 30 minutes”
i have added the above mentioned values and on top of this they have asked me to add etags also. so please let me know how to proceed further and where to add Etags??
Comment out this line if you have, FileETag None
that is
#FileETag None
I dont have that line.. so should i add it??
No need.
i dont have that FileETag None in httpd.conf file so should i add it?? If need to add how to add it please let me know…..
No need to add it.
Reblogged this on Hyper Slice and commented:
Everyone should have something similar in their .htaccess or Apache config.
Hi this is really helpful but in my site ETag has off I want to just on that for which i am writting FileETag MTime Size but this is going to enable.