Automatic update of style sheets Control + F5

Starr Duskk
Starr Duskk used Ask the Experts™
on
Is there a way to force a Control+F5 on a user? We publish our code and the style sheets look horrible until they do a control+F5, but other than putting a message on the screen, how do we trigger the style sheets to update?

thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Director of Technologyy
Commented:
There are several ways to accomplish this.  One way I have used is by using a checksum on the file and adding that as a parameter.  When the file has new css in it, the checksum changes so the browsers know to re-download the file.  

Here is a pretty good article with several other techniques you could use as well.
https://css-tricks.com/strategies-for-cache-busting-css/
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
A URL is defined by the path to the file AND any parametes that are specified so

http://www.yourserver.com/css/style.css
and
http://www.yourserver.com/css/style.css?v=1.0
are seen as different URL's to the browser. If the browser has cached the first and you put the second in your html file the browser will reload the file.

The paramter on the end of the URL does not interfere with normal file download so adding it is benign.

Usual strategies are to include a version number on the end of the url (as shown above) and to change this on each iteration of the css file.

You want it to be static for a specific version so you don't lose the benefits of caching - but when a change is made simply update the version number. Depending on your code environment this can be automated.
Starr DuskkASP.NET VB.NET Developer

Author

Commented:
thanks!
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial