Default to any html file in the folder - javascript

Hi and thank you for your time in advance,
My question is I have a folder /folder-name/ on my server and we change the index.html file in here regularly but for some older browsers and clients they never get the updated information because the old information is cached in their old browser. So I have used this tactic:
How to control web page caching, across all browsers?
But it doesn't work all the time. My idea was to change the file to something different (using date so its unique) and whenever anyone goest to that folder it just defaults to show whatever HTML file is in there. This way the browser would refresh the cache thinking it is a new page each time.
So when the user goes to www.domain.com/folder-name/ it just loads whatever HTML file is in there.
Thanks again for your time.
UPATE:
This is the page: http://www.avrs.com/DMVseminars/
And what happens is certain users (older IE browsers) are caching the schedule and people call in saying they are seeing a schedule 6 months ago. I can't recreate the issue but we get about 5-10 calls a month.

Try adding these tags to your page's <head>. I use these on a site i developed a few years ago and haven't had any cacheing issues reported.
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Reference

Hmmm...
There is a clever fix for this. Have an iframe spanning you whole page, and have it point to your main index.html file.
Like so:
<iframe
href = 'html/index.html'
style = 'width:100%;height:100%;border:none;outline:none;'
></iframe>
Good luck! I hope this works!

Related

Force JavaScript update for Friconix

I embeded Friconix on my web site (a free icon collection like Font Awesome).
I noticed that when new icons are added in the library, they are not available since the JavaScript file is refreshed in cache.
Is there a way to force the client to refresh JavaScript ?
You can't force browsers to clear their cache. But you can change the path to your script. For example, add a GET parameter with version to the path, like this:
<script src="/js/main.js?ver=2"></script>
location.reload has a parameter of type Boolean that specifies a hard reload. (This isn't too reliable - it depends on the browser and safety/security measures in place):
location.reload(true);
Alternatively, use a no-cache meta tag:
<meta http-equiv="Cache-control" content="no-cache" />

How to Clear Browser Cache in Javascript / JQuery or AngularJS [duplicate]

This question already has answers here:
How can I force clients to refresh JavaScript files?
(30 answers)
Closed 4 years ago.
Here we are using Pdf.js extension and Ifram in application,
but we are facing issue with browser cache, its storing in browser but the physical files getting changed by service, and after file content change also its showing previous document details, its not refreshing.
Please provide a solutions to clear cache (Text of webpages you've visited in Google Chrome is removed from your computer. Browsers store elements of webpages to speed up the loading of the webpage during your next visit. — Source) in in Javascript / JQuery or AngularJS
tried with
app.js?123
and
<meta http-equiv="Cache-Control" content="no-cache, no-storeenter code here, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
but not working....???
Versioning the Javascript file is one of the options to force browser to get the updated content of the file. For example:
pdf_v001.js
pdf_v002.js
pdf.js?v=001
pdf.js?v=002
If you have a version control system, you could inject the version number something like this:
<script type="text/javascript" src="pdf_$$REVISION$$.js"></script>
or:
<script type="text/javascript" src="pdf.js?v=$$REVISION$$"></script>
Please refer to this link: How can I force clients to refresh JavaScript files?

Correct way to avoid browser cache with GruntJS

I'm trying to find a good way to release a new version of a single page javascript app without asking clients to refresh their page or clear caches when a new version is deployed
I'm currently revving images / css / js files in my javascript app, so it contains references like scripts/671df76d.main.js and that's great.
So in my webapp v0.1 index.html I have something like this:
<script data-main=“scripts/d7ba3e7b.main” src=“bower_components/requirejs/require.js”></script>
while in a new v0.2 version I have this:
<script data-main=“scripts/671df76d.main” src=“bower_components/requirejs/require.js”></script>
I also experimented with meta tags that might influence caching.
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
But I never found a good solution. Sometimes the updates are shown without requiring a manual refresh from the user, sometimes old content is still being shown. The only way to get the user to see the new content is to ask him to refresh the page.
As users are always visiting the webapp through the index.html, I noticed that sometimes the latest version is picked up (v0.2 with 671df76d.main), but other times after deployment the browser still loads up a previous version.
I'm just wondering how I can guarantee a browser won't have cached my index.html with an old scripts/d7ba3e7b.main.js
It makes sense that the browser can have a cached version the index.html , so it would still refer to old/stale revved javascript sources (obviously something you don't want).
In that sense the fact that you rev your resources is useless.
Am I correct in saying that simply revving up resources inside the index.html is not sufficient and that some additional stuff is needed
html meta tags
htaccess files
webserver configs
What would be a proper way to do this ? Again, the goal being to allow users to see your new version without having to ask them to refresh / clear cache.

javascript refreshing images every 5 seconds crashes web browser?

I have a simple javascript code in an html page, refreshing an image every 5 seconds:
function refresh() {
var unique = new Date();
document.images.EdwinImage.src = "http://192.168.0.125:8002/img?width=800&height=480&rnd=" + unique.getTime();
}
This code works fine on desktop browser, but on Android, it works only for some times then the browser closes without an error message and returns to the home screen.
After the crash, I look in the browser settings (via Settings->Applications->Manage Applications) I noticed the browser application has a 55MB cache... which seems to be the problem... even though I don't need the image to be cached since I request a new one every time. Yes, I have the correct html header to disable caching.
Here are the headers I'm using:
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="PRAGMA" content="no-cache">
<meta http-equiv="expires" content="0">
I'm using Android 2.2 on a Archos HT7V2 and the problems happens on all browsers I tried (stock browser, opera mini, dolphin hd).
How can I solve this problem? Or any ideas of what happened ?
Thank you,

JavaScript file changes deployment

We are having MVC web application. Some of the code is in JavaScript. When we deploy any changes to the JavaScript, the changes are not reflected on the client side. We have to ask clients to do CTRL+F5 to get the changes. Is there a standard way of pushing JavaScript changes to the client side?
You can refer to the files with a version, like this:
<script type="text/javascript" src="myScript.js?v=12345"></script>
The number after v represents your build number, so when a new build pushes, they grab the files again. View source on this page to see the same behavior :) This gives you the benefit of allowing the user to cache the files as long as possible (forever), yet still have them automatically grab any update.
you can try this meta tags
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
You're not saying what server-side language your site is in. A nifty trick from the Rails world is to check the "last modified" time of the file, and to add that as a GET parameter to the URL.
In PHP, it would look like this:
<script type="text/javascript"
src="script.js?time=<?php echo filemtime("script.js");">
(of course, the path you need to give in the filemtime call will probably need to be an absolute one.)

Categories