Implement caching for static resources
This commit is contained in:
parent
0f6fd4dac5
commit
28df906957
@ -41,7 +41,8 @@ self.addEventListener("fetch", function(event) {
|
|||||||
|
|
||||||
function networkOrCache(uri) {
|
function networkOrCache(uri) {
|
||||||
return caches.open("thelounge").then(function(cache) {
|
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) {
|
.then(function(response) {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return cache.put(uri, response.clone()).then(function() {
|
return cache.put(uri, response.clone()).then(function() {
|
||||||
|
@ -39,15 +39,17 @@ module.exports = function() {
|
|||||||
(Node.js ${colors.green(process.versions.node)} on ${colors.green(process.platform)} ${process.arch})`);
|
(Node.js ${colors.green(process.versions.node)} on ${colors.green(process.platform)} ${process.arch})`);
|
||||||
log.info(`Configuration file: ${colors.green(Helper.getConfigPath())}`);
|
log.info(`Configuration file: ${colors.green(Helper.getConfigPath())}`);
|
||||||
|
|
||||||
|
const staticOptions = {
|
||||||
|
redirect: false,
|
||||||
|
maxAge: 86400 * 1000,
|
||||||
|
};
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
.disable("x-powered-by")
|
.disable("x-powered-by")
|
||||||
.use(allRequests)
|
.use(allRequests)
|
||||||
.use(index)
|
.use(index)
|
||||||
.use(express.static("public"))
|
.use(express.static(path.join(__dirname, "..", "public"), staticOptions))
|
||||||
.use("/storage/", express.static(Helper.getStoragePath(), {
|
.use("/storage/", express.static(Helper.getStoragePath(), staticOptions));
|
||||||
redirect: false,
|
|
||||||
maxAge: 86400 * 1000,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// This route serves *installed themes only*. Local themes are served directly
|
// This route serves *installed themes only*. Local themes are served directly
|
||||||
// from the `public/themes/` folder as static assets, without entering this
|
// from the `public/themes/` folder as static assets, without entering this
|
||||||
|
Loading…
Reference in New Issue
Block a user