Node.js: abilitare il caching delle risorse statiche di ExpressJS

Node.js: abilitare il caching delle risorse statiche di ExpressJS

In ExpressJS possiamo abilitare il caching delle risorse statiche.

La soluzione รจ la seguente:


'use strict';

const express = require('express');
const app = express();

 const makeCache = function(dirname, age) {
    return express.static(path.join(__dirname, dirname), {
      maxAge: age,
      dotfiles: 'ignore',
      etag: false
    });
};

app.use('/public', makeCache('/public', '30d'));

Torna su