TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-12-2008, 08:10 PM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default 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
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 12-12-2008, 10:20 PM   #2 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default 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
etoolbox is offline  
Reply With Quote
Old 12-13-2008, 03:58 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by etoolbox View Post
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
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 12-12-2008, 10:48 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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>
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-12-2008, 11:25 PM   #5 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

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.
etoolbox is offline  
Reply With Quote
Old 12-13-2008, 02:19 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-15-2008, 12:17 AM   #7 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

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.
etoolbox is offline  
Reply With Quote
Old 12-18-2008, 01:22 AM   #8 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 15
Thanks: 2
Mathew is on a distinguished road
Default

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.
Mathew is offline  
Reply With Quote
Old 12-18-2008, 01:26 AM   #9 (permalink)
The Wanderer
Newcomer 
 
etoolbox's Avatar
 
Join Date: Dec 2008
Location: Auckland, NZ
Posts: 24
Thanks: 0
etoolbox is on a distinguished road
Default

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
etoolbox is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck with timestamps KingOfTheSouth General 6 10-14-2008 12:50 AM
Adding Timestamps in SQL? Theo Absolute Beginners 2 08-23-2008 04:27 AM
unix timestamps and group by webosb MySQL & Databases 3 02-13-2008 02:41 PM


All times are GMT. The time now is 07:22 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design