Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a web app without suffering cached CSS issues?

Say I've got a web app. I add some features to it, and those features require additions to some existing CSS files on my web server. I deploy my new features and CSS additions to my server, and they work great. Users visiting the site will probably have cached CSS in their browser, though, which means the new features will look broken/weird until either they manually refresh the page or their cache expires. The problem might be even worse if there's a cache server between my server and the user, in which case even a manual refresh won't help (I don't think).

Is there a common way to avoid this?

EDIT: I'm running on ASP.NET 4.0.

like image 254
Tom Hamming Avatar asked Jun 29 '12 19:06

Tom Hamming


People also ask

How do I update my CSS?

If your site is not live yet, and you just want to update the stylesheet at your pleased intervals, then use this: Ctrl + F5 . On Mac OS (in Chrome) use: Cmd + Shift + R . This will force your browser to reload and refresh all the resources related to the website's page.

How do I force a browser to refresh CSS?

Anytime you make changes to CSS, JavaScript and are viewing the page you've updated - you will see this concern. You can force a refresh by pressing CTRL+F5 on the browser and that will get the latest version.

How do you force the browser to reload cached .JS .CSS files to reflect the latest changes to those files?

It works, all the time, for everyone. But, if you're not using it, and you just need to reload that one CSS or JS file occasionally in your own browser... just open it in its own tab and hit SHIFT-reload (or CTRL-F5)!


1 Answers

You can add an arbitrary name value pair to the end of your css request and it will act as if it's not cached. For instance:

<link media="all" href="myhomepage.css?sid=1" type="text/css" rel="stylesheet">

When you make a change change the sid value.

like image 136
scrappedcola Avatar answered Nov 15 '22 07:11

scrappedcola