Koa.js Adding HTTP Static Cache to App in Browser Using koa-static-cache Library Full Project For Beginners

 

Welcome folks today in this blog post we will be implementing http static cache inside application in browser using koa-static-cache library in koa.js.All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the below library using the npm command as shown below

 

 

npm i koa-static-cache

 

 

After installing this library you can make an app.js file and copy paste the following code

 

 

app.js

 

 

var koa = require('koa');
var app = koa();

var path = require('path');
var staticCache = require('koa-static-cache');

app.use(staticCache(path.join(__dirname, 'public'), {
   maxAge: 365 * 24 * 60 * 60  //Add these files to caches for a year
}))

app.listen(3000);

Leave a Reply