I have a web-app I'm allowing users to add scripts to. These scripts are written in JavaScript and run in the user's browser. When developing new scripts to run locally, I've added a button to the app that allows you to load it from a locally running web server, (i.e. so you'd click on it and enter http://path.to.my.pc:12345/script.js). My app will fetch this script and append to the DOM.
These scripts are assumed to be ES6 modules and Chrome happily handles those, recursively importing correctly.
However when running locally, I also wanted the ability for users to "refresh" as they're developing such that the app will hit their server again to redownload the scripts. Chrome does not seem to want to do this. Specifically, despite the fact that my local test server has specified no-store as Cache-Control, Chrome doesn't care. Even if I cacheBust script.js (i.e.http://blah/script.js?cb=randomInt), this cacheBust parameter is not recursively passed to the imports.
Here's the text of my locally running dev server:
const express = require("express");
const serveStatic = require("serve-static");
const morgan = require("morgan");
function setHeaders(res, path) {
res.setHeader('Cache-Control', 'no-store');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
}
const app = express();
app.use(morgan('combined'));
app.use(serveStatic('./', { setHeaders });
app.listen(12345);
Is there something else I can do? I really don't want to force my users to run webpack. The idea is to keep this as simple and stupid as possible so they can just focus on writing their scripts.
Edit Update: Checking 'Disable Caching' in Devtools also does not cause Chrome to actually... not cache.
from Chrome Ignoring Cache-Control no-store directive?
No comments:
Post a Comment