Mystical Posted July 28, 2011 Posted July 28, 2011 I ran across this on my travels and it works like a charm! I can see a massive increase in my page loading speed. Add this to your .htaccess file. # Cache static content for 1 MONTH <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|css|js|txt|xml)$"> Header set Cache-Control "public" Header set Cache-Control "max-age=2592000, public" Header unset Last-Modified </FilesMatch> # Remove ETag headers Header unset ETag FileETag None # compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript Quote
Curt Posted July 28, 2011 Posted July 28, 2011 Anyone got any thing to say about this ?....its not something im familiar with. I would like to use it if it works as you say :) Any downside to it ? Quote
The Spirit Posted July 28, 2011 Posted July 28, 2011 Can anyone explain what this does exactly? :) Quote
US Vice Posted July 28, 2011 Posted July 28, 2011 The first part of it, as it states, seems to cache images and other static material for a month as indicated by the max-age, so this means static content doesn't need to be reloaded everytime? The other part looks like it compresses content. I'm just guessing at what the processes are. Quote
Curt Posted July 28, 2011 Posted July 28, 2011 lol...yea i read the comments aswell... Seems like something nice to add.... would like to know about any downsides before I try it out though.. Quote
US Vice Posted July 28, 2011 Posted July 28, 2011 A potential downside is that if you have an image but then update this image and keep the same filename, it may not be updated for the user if they visited the page within the last month. Quote
Mystical Posted July 28, 2011 Author Posted July 28, 2011 lol...yea i read the comments aswell... Seems like something nice to add.... would like to know about any downsides before I try it out though.. It is nice to add believe me. It made my game 100 times faster than it was. The only downside was mentioned by US Vice. If you have all your graphics in place and don't intend to change them like me then you are fine. You could always change the file name of the graphics file if you do decide to update a graphic. Quote
Curt Posted July 28, 2011 Posted July 28, 2011 Ah i see, I actually added it to my site and I do see a nice speed increase. Would refreshing not show the new images ?...I do have some image updates still to be made. if not i could simply lower the monthly timer temporarily :) Nice addition Mystical :D UPDATE: Refreshing will show the new image :) It did for me anyway just now....lol Quote
W3Theory || Peter Posted July 28, 2011 Posted July 28, 2011 I have tested this out as well, I must say I do see a difference. Very nice catch there mystical. Though may I ask where you got it from? Quote
lucky3809 Posted July 28, 2011 Posted July 28, 2011 Excellent find, thank you for sharing, definite seen a huge difference with my images loading! Quote
bluegman991 Posted July 28, 2011 Posted July 28, 2011 If regular image refreshing doesnt work you can add a random number or timestamp to the query and that'll refresh it. (http://www.website.com/image.png?32128718732) Quote
Mystical Posted July 29, 2011 Author Posted July 29, 2011 I have tested this out as well, I must say I do see a difference. Very nice catch there mystical. Though may I ask where you got it from? I just did a search on how to improve a web sites speed with .htaccess and found the link here : http://forums.hostgator.com/speed-up-your-site-htaccess-t132870.html?amp I found it a while ago but kept forgetting to post it here for everyone. It does work pretty well! My site was slower than molasses until I added that code. Gotta love the internet and smart people! Quote
Dave Posted July 29, 2011 Posted July 29, 2011 This is a very commonly known caching method. I would suggest anyone with a production site to be using some form of caching, during development it's not really needed due to how much you're changing the pages and other various elements and you don't want to be having to clear your cache every few seconds. In essence it's just forcing your browser to use the images already in your cache before checking if their are news ones of the server. This means the site is basically being loaded from your computer and the page content is being filled in by the server. Don't quote me on that, it's how I understand caching. Quote
Jeff Posted July 29, 2011 Posted July 29, 2011 Ah i see, I actually added it to my site and I do see a nice speed increase. Would refreshing not show the new images ?...I do have some image updates still to be made. if not i could simply lower the monthly timer temporarily :) Nice addition Mystical :D If your using something like this is a good idea to include a version or date in the image name. Helps avoid problems when updating the image :) Quote
Diesl Posted August 6, 2011 Posted August 6, 2011 @Curt, yes you can lower the timer. You can also specify different rules for different content types. In Mystical's script, it categorizes all files under one rule. But perhaps you will be updating images or CSS files more than once per month. If that is the case, you could make a separate rule just for them and have a different timer. You could potentially have different rules for each file type if you'd like. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.