I had some problems with browser caching. When css, js, image
files change the content but not the name, we must send to browser to download the new one and discard cached files.
Just pressing F5 or something like this the new files are not being updated.
There is a way to force browser forget the cache and download the new version of files?
Some people with this "issue"
This and this pages gave me an idea and I want to share it. :)
. My directory structure is this:
website/
|- libs/
|- css/
|- js/
|- imgs/
|- system/
|- site/
|- .htacces
|- index.php
so, we can use the .htacces
file to "fool" the browser like this:
RewriteRule ^libs\.v[0-9]{1,}(.*) libs/$1
RewriteRule ^(.*)\.v[0-9]{1,}\.css$ $1.css
And, on html
files use this:
<link rel="stylesheet" type="text/css" media="all" href="path/to/libs/css/style.v2.css" />
<script type="text/javascript" src="path/to/libs/js/javascripts.v1.js"></script>
<img src="path/to/libs/imgs/logo.v5.png" alt="Logo" />
or
<link rel="stylesheet" type="text/css" media="all" href="path/to/libs.v1/css/style.css" />
<script type="text/javascript" src="path/to/libs.v1/js/javascripts.js"></script>
<img src="path/to/libs.v1/imgs/logo.png" alt="Logo" />
This is working fine for me.. whem I change something on a file I just add
or change
the number after .v
like: .v1
, .v2
Reason: this trick make the browser see "http://www.mydomain.com/libs/css/style.v1.css" and than.. the cache/browser will believe that is a new file.. ;)
I hope to help someone.. any suggestions will be Welcome