473,386 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
2 4273
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jonathan Driller | last post by:
I am attempting to block repeat downloads from a site. I need to have a landing page pass a referer to a secured page. I have tried a meta refresh redirect and several Javascript redirect...
1
by: mwk24 | last post by:
Hi all, I have standard AJAX script that calls a php file to load the latest information and uses xmlHTTP.responseText to write it to innerHTML of a div by id. It works fine on IE/firefox, but I'm...
1
by: mwk24 | last post by:
Hi all, I have standard AJAX script that calls a php file to load the latest information and uses xmlHTTP.responseText to write it to innerHTML of a div by id. It works fine on IE/firefox, but I'm...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I force a reload from the server/prevent caching?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.