Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » How to set cache expiration?

How to set cache expiration?

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Feb 2010
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
How to set cache expiration?

I'm using Firebug to analyse my website's performance, the main problem is 'Leverage browser caching'. How do I set a cache expiration time for images? And can it be done quickly?, there are 30+ that I need to do!


Thanks!
Reply With Quote
  #2 (permalink)  
Old
scott2500uk's Avatar
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
you could use a htaccess file and use something like this:

Code:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 1 years"
ExpiresByType image/jpeg "access plus 1 years"
ExpiresByType image/png "access plus 1 years"
ExpiresByType image/x-icon "access plus 1 years"
ExpiresByType text/css "access plus 1 years"
ExpiresByType text/javascript "access plus 1 years"
ExpiresByType application/x-javascript "access plus 1 years"
ExpiresByType application/x-shockwave-flash "access plus 1 years"
</IfModule>
This sets the expiry date of all the above file types to way in the future.

Because images dont change often then its safe to set to a year in the future.

CSS and JavaScript files on the other hand may change in a months time so best thing to do is add a version number to the URL of the style sheet so that when u change version number the browser sees it as a new file and caches the new file.

e.g. http://somehost/style/mystylesheet.css?v=1.0
Reply With Quote
  #3 (permalink)  
Old
New Member
 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by scott2500uk View Post
you could use a htaccess file and use something like this:

Code:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 1 years"
ExpiresByType image/jpeg "access plus 1 years"
ExpiresByType image/png "access plus 1 years"
ExpiresByType image/x-icon "access plus 1 years"
ExpiresByType text/css "access plus 1 years"
ExpiresByType text/javascript "access plus 1 years"
ExpiresByType application/x-javascript "access plus 1 years"
ExpiresByType application/x-shockwave-flash "access plus 1 years"
</IfModule>
This sets the expiry date of all the above file types to way in the future.

Because images dont change often then its safe to set to a year in the future.

CSS and JavaScript files on the other hand may change in a months time so best thing to do is add a version number to the URL of the style sheet so that when u change version number the browser sees it as a new file and caches the new file.

e.g. http://somehost/style/mystylesheet.css?v=1.0

where i add this code..??? between <heade> </head> tag..??
Reply With Quote
  #4 (permalink)  
Old
New Member
 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Reply

Quote:
Originally Posted by abrica View Post
i'm using firebug to analyse my website's performance, the main problem is 'leverage browser caching'. How do i set a cache expiration time for images? And can it be done quickly?, there are 30+ that i need to do!


Thanks!
try checking the tools section and disabling the catche jump before u proceed
Reply With Quote
Reply

Bookmarks

Tags
cache, expiration, html, image


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GRRR!!!! ERror help please! stormshadow PHP 4 12-06-06 09:05 PM
ASP upload prob minority ASP 1 06-27-05 09:35 AM
Setting a cooke (time it expires) mcrob PHP 4 04-27-05 01:13 PM


All times are GMT -5. The time now is 11:41 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.