Handling the Cache problem
As you know applications like gmail / yahoomail they constantly keep changing their js/css and when you login you dont have to clear your browser cache to see the new changes, they are automatically shown to you.
How do they do this? I see there are two approaches:
1) in your code where you specify the path of the js/css you append time with a querystring that will force your browser to load the lastest js/css no matter it has been modified or not.
2) You use the "Pragma: No-cache" Tag in your page.
But the problem in these approaches is that your application makes an HTTP request every time its called since it assumes the file is new.
So whats the solution?
Any help is appreciated.
Don't know how they do it, but I just thought of this: have the main app get the last mod time of the file in question, and use that as a (unused) query string value.
This way the browser could cache it until the resource file is changed and gets a new mod time.
$jsFile = '/path/to/file.js';
$jsFileUrl = $jsFile . "?v=" . file_mtime($_SERVER['DOCUMENT_ROOT'] . $jsFile);
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)