How to update a web application without CSS caching issues?

Say I have a web application. I am adding some functions to it, and these functions require adding to some existing CSS files on my web server. I am deploying my new features and adding CSS to my server and they work great. Visitors to the site probably have cached CSS in their browser, but this means that the new features will look broken / strange until they manually refresh the page or expire. The problem could be even worse if there is a cache server between my server and the user, in which case even updating manually will not help (I don’t think).

Is there a general way to avoid this?

EDIT: I am running ASP.NET 4.0.

+5
source share
4 answers

You can add an arbitrary name-name pair at the end of your css request and it will act as if it is not cached. For instance:

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

When changing the change, change the sid value.

+6
source

Of course, I don’t know your setup, since you don’t mention it, but if you have a container for servlets like Tomcat, I would advise you to take a look at Jawr . His goal, from the website: "Jawr is a custom packaging solution for Javascript and CSS ...

, , @scrappedcolas. URL-, (- scripts_A5F68E2.js), , . , , , .

+1

, , . , yawr.

, vcs - , , .

PHP Python , , . Java .NET .

.

+1

PHP Apache:

function cssInclude($file) {
    $fileMTime = filemtime($_SERVER['DOCUMENT_ROOT']."/media/css/".$file.".css");
    return "<link rel=\"stylesheet\" href=\"/media/css/{$file}.{$fileMTime}.css\"
}

<head>:

<?= cssInclude("style"); ?>

.htaccess:

RewriteEngine on
RewriteRule ^media/(js|css|img|font)/(.+)\.(\d+)\.(js|css|png|jpg|gif)$ /media/$1/$2.$4 [L]

, , . CSS ?, style.css?12313123, , , , , (, ).

style.123123123.css, , , , .

, .htaccess - .

Of course, this means that you are reading material from the file system, but if you have a caching layer, this is done only once for the update.

0
source

All Articles