Cache gravatar requests
This commit is contained in:
@ -19,14 +19,14 @@ const router = new Router();
|
||||
// }
|
||||
// });
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
router.get('/service-worker.js', async (ctx) => {
|
||||
ctx.set('Content-Type', 'application/javascript');
|
||||
ctx.set('Cache-Control', `max-age=${30}`);
|
||||
const stats = await sendfile(ctx, path.join(__dirname, './static/service-worker.js'));
|
||||
if (process.env.NODE_ENV === 'production') ctx.set('Cache-Control', `max-age=${30}`);
|
||||
await sendfile(ctx, path.join(__dirname, './static/service-worker.js'));
|
||||
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
router.get('/static/*', async (ctx) => {
|
||||
ctx.set({
|
||||
'Cache-Control': `max-age=${356*24*60*60}`,
|
||||
|
@ -29,5 +29,15 @@
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/bundle.js"></script>
|
||||
<script type="text/javascript">
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/service-worker.js')
|
||||
.then(function(reg) {
|
||||
console.log('SW registration succeeded');
|
||||
}).catch(function(error) {
|
||||
console.log('SW registration failed: ' + error);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/*
|
||||
Copyright 2014 Google Inc. All Rights Reserved.
|
||||
|
||||
@ -52,6 +54,7 @@ Cache.prototype.addAll||(Cache.prototype.addAll=function(t){function e(t){this.n
|
||||
|
||||
// Assets
|
||||
global.toolbox.router.get(/\/static\//, global.toolbox.cacheFirst);
|
||||
global.toolbox.router.get('/(.*)', global.toolbox.fastest, {origin: 'https://secure.gravatar.com'});
|
||||
|
||||
// API GET calls
|
||||
global.toolbox.router.default = global.toolbox.networkFirst;
|
||||
|
Reference in New Issue
Block a user