Reputation: 2178
I have a little bookmarklet that simply loads a remote JS script from my website to add a button to page elements on Reddit. Pushing the button sends to my site for storage, though that's not the important part.
The issue is that the the webpage where my script loads is "helpfully" cached which makes it REALLY hard to debug and update. Hitting CTRL+F5 doesn't seem to fix it. Neither does loading the JS manually in another tab. I don't know what the conditions are, but it will EVENTUALLY work... but it's slowing me down pretty badly. How can I manually force it to retrieve a new copy of the script from my webpage instead of the cache? This is in Chrome.
Here is my bookmarklet
javascript: (function () {
if (document.getElementById('darmokPending') == null){
var jsCode = document.createElement('script');
jsCode.setAttribute('src', 'https://mypage/scripts/redditer.js');
document.body.appendChild(jsCode); }}());
The code is loaded properly from the remote location, but then it gets cached. Help!
Upvotes: 0
Views: 121
Reputation: 224904
The correct solution is to use a Cache-Control
response header on the script:
Cache-Control: public, must-revalidate
But if you can’t change response headers for whatever reason, you can use retro cachebusting by making changes to the URL:
jsCode.src = 'https://mypage/scripts/redditer.js?_=' + Date.now();
Upvotes: 1