TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   CSS Timestamps (http://www.talkphp.com/general/3761-css-timestamps.html)

Orc 12-12-2008 08:10 PM

CSS Timestamps
 
I have seen css files that have timestamp parameters, or so it seems to be a timestamp, since it's the same length, and such.

e.g. example.com/foo.css?102193243

etoolbox 12-12-2008 10:20 PM

CSS/JS Timestamps example
 
I've written about this here: http://www.electrictoolbox.com/javas...le-timestamps/

You need to be wary of doing what I suggest if your site is busy though because there's overhead in checking timestamps of multiple files for each page request. In those instances it might be better to just do e.g. foo.css?some-unique-value

Wildhoney 12-12-2008 10:48 PM

Could this not be achieved with .htaccess? Something like the following in the CSS directory:

Code:

<Files *>
Header set Cache-Control: "private, pre-check=0, post-check=0, max-age=0"
Header set Expires: 0
Header set Pragma: no-cache
</Files>


etoolbox 12-12-2008 11:25 PM

But then the browser would never cache it, and have to download the CSS/JS file on every page request. Not really ideal. The idea with the ?value at the end of the filename is that you can control when the browser *must* download it and it will then continue to cache that version of the file.

Orc 12-13-2008 03:58 AM

Quote:

Originally Posted by etoolbox (Post 20473)
I've written about this here: http://www.electrictoolbox.com/javas...le-timestamps/

You need to be wary of doing what I suggest if your site is busy though because there's overhead in checking timestamps of multiple files for each page request. In those instances it might be better to just do e.g. foo.css?some-unique-value

That was you? I was already on that site. ;P

Wildhoney 12-13-2008 02:19 PM

Coincidence!

How about the Apache module mod_expires? I've used it once or twice, but never for caching. However, you can set any HTTP header with an expiration time, so it should be just fine.

etoolbox 12-15-2008 12:17 AM

That will set the time limit for caching, but you still can't force the browser to request a new version when you change the contents of the stylesheet. This doesn't matter so much for trivial changes, but if you make major changes you're still going to want to either rename the file or use ?something to effectively rename the file. That way on the the next page request the browser gets the updated version and everything renders correctly. Otherwise there may be layout issues until the cached copy expires.

Mathew 12-18-2008 01:22 AM

I personally version my css files so I would start with style001.css and so on.

This way I can set the maximum expires time and if I need to make any changes I can upload the new file as style002.css.

etoolbox 12-18-2008 01:26 AM

That's what I used to do but I found it a bit of a hassle having multiple versions of files with different names, especially if you're doing a lot of CSS updates. I now version them after the date and time like e.g. style.css?20081218.1424


All times are GMT. The time now is 11:39 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0