By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

Can I force the client to stop caching old stylesheets and javascript?

P: n/a
Can I force the client to stop caching old stylesheets and javascript?

In my dynamic web-site, I need to force the client to stop caching old
versions of my stylesheets and javascript. Can I do this by including
a querystring with the url with each external stylesheet and script
file declaration?

For example:

<link type="text/css" rel="stylesheet" href="../images/menu.css?
v=1" />
<script type="text/javascript" src="../javascript/menu.js?v=1"></
script>

This is far easier, for me, than coding the web-server to change the
file headers. I just want confirmation that this will work. It seems
obvious that it should but I'm curious as to why I've never come
across this technique before.

Oct 16 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
On Tue, 16 Oct 2007 15:50:41 +0200, mark4asp <ma******@gmail.comwrote:
Can I force the client to stop caching old stylesheets and javascript?

In my dynamic web-site, I need to force the client to stop caching old
versions of my stylesheets and javascript. Can I do this by including
a querystring with the url with each external stylesheet and script
file declaration?

For example:

<link type="text/css" rel="stylesheet" href="../images/menu.css?
v=1" />
<script type="text/javascript" src="../javascript/menu.js?v=1"></
script>

This is far easier, for me, than coding the web-server to change the
file headers.
Shouldn't be...
I just want confirmation that this will work. It seems
obvious that it should but I'm curious as to why I've never come
across this technique before.
It works (well, as long as you keep changing the query string), and is
widely in use.
--
Rik Wasmus
Oct 16 '07 #2

P: n/a
mark4asp wrote:
Can I force the client to stop caching old stylesheets and javascript?

In my dynamic web-site, I need to force the client to stop caching old
versions of my stylesheets and javascript. Can I do this by including
a querystring with the url with each external stylesheet and script
file declaration?
Yes, but that's evil. Fortunately, you may be punished by a low google
rank! Crawlers assume that a URI uniquely identifies a resource.

Use the HTTP headers (e.g. set expiration to zero second). If the page is
generated by a script or contains SSI, your server should use the correct
headers by default.
If the page is static, then, why preventing caching? To improve the page
hits statistics? That would be stupid and evil.
What is it for?

I just want confirmation that this will work.
It will work as using pseudonyms to commit evil deeds reduces the chance
of being identified.
It seems obvious that it should but I'm curious as to why I've never come
across this technique before.
Because, modifying HTTP headers is much nicer, much more civilized, and
much more natural. It's the direct, obvious, fine, standardized way to
control caching. Your way, is worse than failure:
http://worsethanfailure.com/Default.aspx
--
If you've a question that doesn't belong to Usenet, contact me at
<ta*****************@yahoDELETETHATo.fr>
Oct 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.