opti: 增加浏览器对 js css 缓存,加快刷新页面后的访问速度

This commit is contained in:
suxiaoxin 2017-11-05 16:17:00 +08:00
parent c9d15081f4
commit 60967f715f

View File

@ -44,6 +44,7 @@ app.use( async (ctx, next) => {
app.use( async (ctx, next)=>{ app.use( async (ctx, next)=>{
if(ctx.path.indexOf('/prd') === 0){ if(ctx.path.indexOf('/prd') === 0){
ctx.set('Cache-Control', 'max-age=8640000000');
if(yapi.commons.fileExist( yapi.path.join(yapi.WEBROOT, 'static', ctx.path+'.gz') )){ if(yapi.commons.fileExist( yapi.path.join(yapi.WEBROOT, 'static', ctx.path+'.gz') )){
ctx.set('Content-Encoding', 'gzip') ctx.set('Content-Encoding', 'gzip')
ctx.path = ctx.path + '.gz'; ctx.path = ctx.path + '.gz';
@ -51,6 +52,7 @@ app.use( async (ctx, next)=>{
} }
await next() await next()
}) })
app.use(koaStatic( app.use(koaStatic(
yapi.path.join(yapi.WEBROOT, 'static'), yapi.path.join(yapi.WEBROOT, 'static'),
{index: indexFile, gzip: true} {index: indexFile, gzip: true}