Implement caching for static resources

This commit is contained in:
Pavel Djundik 2018-06-06 12:19:51 +03:00
parent 0f6fd4dac5
commit 28df906957
2 changed files with 9 additions and 6 deletions

View file

@ -41,7 +41,8 @@ self.addEventListener("fetch", function(event) {
function networkOrCache(uri) {
return caches.open("thelounge").then(function(cache) {
return fetch(uri)
// Despite the "no-cache" name, it is a conditional request if proper headers are set
return fetch(uri, {cache: "no-cache"})
.then(function(response) {
if (response.ok) {
return cache.put(uri, response.clone()).then(function() {

View file

@ -39,15 +39,17 @@ module.exports = function() {
(Node.js ${colors.green(process.versions.node)} on ${colors.green(process.platform)} ${process.arch})`);
log.info(`Configuration file: ${colors.green(Helper.getConfigPath())}`);
const staticOptions = {
redirect: false,
maxAge: 86400 * 1000,
};
const app = express()
.disable("x-powered-by")
.use(allRequests)
.use(index)
.use(express.static("public"))
.use("/storage/", express.static(Helper.getStoragePath(), {
redirect: false,
maxAge: 86400 * 1000,
}));
.use(express.static(path.join(__dirname, "..", "public"), staticOptions))
.use("/storage/", express.static(Helper.getStoragePath(), staticOptions));
// This route serves *installed themes only*. Local themes are served directly
// from the `public/themes/` folder as static assets, without entering this