You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am from China, my English is not very good, this article is translated by Google, please forgive me if you can't understand it.
Can you support negotiated cache? Automatically generate and add ETag and Last-Modified request headers, and process If-Modified-Since and If-None-Match request headers to implement this function, which meets the basic functions of a static resource server.
Currently I implement this function like this:
constKoa=require('koa')conststatic=require('@koa/static')// koa-send is used internallyconstapp=newKoa()letkoaStaticMiddlewareapp.use((ctx,next)=>{if(!koaStaticMiddleware){koaStaticMiddleware=static('./public',{setHeaders(res,path,stats){constfileHash=getFileHash(path)res.setHeader('Cache-Control','no-cache')res.setHeader('ETag',fileHash)res.setHeader('Last-Modified',stats.mtime.toUTCString())constetag=ctx.headers['if-none-match']constlastModified=ctx.headers['if-modified-since']if((etag&&etag===fileHash)||(lastModified&&lastModified===stats.mtime.toUTCString())){ctx.throw(304,'Not Modified')}}})}returnkoaStaticMiddleware(ctx,next)})functiongetFileHash(filePath){// ...}
The text was updated successfully, but these errors were encountered:
Hello, I am from China, my English is not very good, this article is translated by Google, please forgive me if you can't understand it.
Can you support negotiated cache? Automatically generate and add ETag and Last-Modified request headers, and process If-Modified-Since and If-None-Match request headers to implement this function, which meets the basic functions of a static resource server.
Currently I implement this function like this:
The text was updated successfully, but these errors were encountered: