I have a php site running in cloud server.When ever i add new files css, js or images the browser is loading the same old js, css and image files stored in cache.
My site has a doctype and meta tag as below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0)">
<meta http-equiv="Site-Enter" content="blendTrans(Duration=1.0)">
<meta http-equiv="Site-Exit" content="blendTrans(Duration=1.0)">
Because of the above doctype and meta code am i loading the same files cached in browser instead of new one
Prevent browser cache is not a good idea depending on the case. Looking for a solution I found solutions like this:
the problem here is that if the file is overwritten during an update on the server, which is my scenario, the cache is ignored because timestamp is modified even the content of the file is the same.
I use this solution to force browser to download assets only if its content is modified:
You can try this:
Hopefully it will help prevent Cache, if any!
I had problem with caching my css files. Setting headers in PHP didn't help me (perhaps because the headers would need to be set in the stylesheet file instead of the page linking to it?).
I found the solution on this page: https://css-tricks.com/can-we-prevent-css-caching/
The solution:
Append timestamp as the query part of the URI for the linked file.
(Can be used for css, js, images etc.)
For development:
<link rel="stylesheet" href="style.css?<?php echo date('Y-m-d_H:i:s'); ?>">
For production (where caching is mostly a good thing):
<link rel="stylesheet" type="text/css" href="style.css?version=3.2">
(and rewrite manually when it is required)
Or combination of these two:
EDIT:
Or prettier combination of those two:
try this
Here, if you want to control it through HTML: do like below Option 1:
And if you want to control it through PHP: do it like below Option 2:
AND Option 2 IS ALWAYS BETTER in order to avoid proxy based caching issue.