Caching

Our static file requirements are minimal; the only static content we serve would be the components used on the client side of our application. In order to cache our static files/components, let's make a simple change to vision-web/lib/express/index.js. We set the maxAge property to a week, which we store in config, as follows:

app.use(express.static('public',
  { maxAge: config.get('express:staticCache') }));
app.use(express.static('public/components',
  { maxAge: config.get('express:staticCache') }));
app.use('/bootstrap',express.static('public/components/bootstrap/docs/assets/css',
  { maxAge: config.get('express:staticCache') }));
app.use('/sockets',
  express.static('public/components/socket.io-client/dist/', { maxAge: config.get('express:staticCache') }));

Let's add the config value, staticCache, to vision-web/config/*.json, as follows:

  "express": {
    "port": 8443,
    "staticCache" : 6048000000
  },

Now, when we hit our application, the response headers will have a cache-control header. If you visit the homepage for our application and check the response headers via your browser tools for any of the resources served, you should see:

Cache-Control:public, max-age = 86400
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.29.112