Question

Part of the application we are developing is about to be provided to the third-party websites as a widget with a simple code like:

<script src="ourdomain/script.js" type="text/javascript"></script>
<div id="our-id"></div>

Is there any way to provide the workaround for the cases when we update the script.js code fixing, for instance, critical bugs, and on the next load user doesn't have caching to prevent him to get the new version?

In the other words, is there any analog to timestamp etags in this case?

Thanks in advance!

Was it helpful?

Solution

Well one way (not the best) is to force them to load the script on each load, so no caching is happening

<script type="text/javascript">
    document.write("<script src='ourdomain/script.js?" + (new Date().getTime()) + "' type='text/javascript'></script>");
</script>
<div id="our-id"></div>

The other could be an iframe that loads all the assets from your site, so if you update the JS you can give it a unique name so it forces the browser to get it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top