-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
// serve (serve dev and watch files) | ||
// serve:dist (serve build files) | ||
// deploy (deploy app at github pages) | ||
// minify-js (js minify and sourcemaps) | ||
// minify-css (css minify and sourcemaps) | ||
// minify-html | ||
|
@@ -19,7 +18,6 @@ const uglify = require('gulp-uglify-es').default; | |
const minifycss = require('gulp-clean-css'); | ||
const htmlmin = require('gulp-htmlmin'); | ||
const util = require('gulp-util'); | ||
const ghPages = require('gulp-gh-pages'); | ||
|
||
|
||
// File where the favicon markups are stored | ||
|
@@ -70,14 +68,6 @@ gulp.task('serve:dist', () => { | |
gulp.watch([src.dev.html, src.dev.css, src.dev.js]).on('change', reload); | ||
}); | ||
|
||
gulp.task('deploy', () => { | ||
gulp.src('./dist/**/*') | ||
.pipe(ghPages({ | ||
force: true, | ||
remoteUrl: '[email protected]:Tsuna-mi/mws-restaurant.git', | ||
branch: 'master' | ||
})); | ||
}); | ||
|
||
// minify-js | ||
gulp.task('minify-js', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const version = '1.0.13'; | ||
const staticCacheName = 'msw-restrev-'; | ||
const staticCache = staticCacheName + version; | ||
const contentImgsCache = `${staticCacheName}imgs`; | ||
const allCaches = [ | ||
staticCache, | ||
contentImgsCache | ||
]; | ||
|
||
function servePhoto(request) { | ||
// Regex to store the assets images without type | ||
const storageUrl = request.url.replace(/-(s|m|l|xl|m@2x|s@2x)\.(jpg|webp|png|svg)$/, ''); | ||
|
||
return caches.open(contentImgsCache) | ||
.then(cache => cache.match(storageUrl) | ||
.then((response) => { | ||
if (response) return response; | ||
|
||
return fetch(request).then((networkResponse) => { | ||
cache.put(storageUrl, networkResponse.clone()); | ||
return networkResponse; | ||
}).catch(() => console.log('Fetch fail', request.url)); | ||
})); | ||
} | ||
|
||
self.addEventListener('install', (event) => { | ||
// Open a cache and add the static resources | ||
event.waitUntil(caches.open(staticCache).then((cache) => { | ||
cache.addAll([ | ||
'/', | ||
'/js/dbhelper.js', | ||
'/js/main.js', | ||
'/js/restaurant_info.js', | ||
'/restaurant.html', | ||
'/assets/data/restaurants.json', | ||
'/manifest.json', | ||
'/assets/css/styles.css', | ||
'https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css', | ||
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700', | ||
'https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2', | ||
'https://fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmSU5fBBc4AMP6lQ.woff2' | ||
]); | ||
cache.keys().then(keys => console.log(keys)); | ||
})); | ||
}); | ||
|
||
self.addEventListener('activate', (event) => { | ||
// Remove old cache versions | ||
event.waitUntil(caches.keys().then((cacheNames) => { | ||
Promise.all(cacheNames.filter(cacheName => | ||
cacheName.startsWith(staticCacheName) && !allCaches.includes(cacheName)) | ||
.map(cacheName => caches.delete(cacheName))); | ||
})); | ||
}); | ||
|
||
self.addEventListener('fetch', (event) => { | ||
const requestUrl = new URL(event.request.url); | ||
if (requestUrl.origin === location.origin) { | ||
if (requestUrl.pathname.startsWith('/assets/img/')) { | ||
event.respondWith(servePhoto(event.request)); | ||
return; | ||
} | ||
} | ||
|
||
// Check if we have the request cached or not | ||
event.respondWith(caches.match(event.request) | ||
.then(response => response || fetch(event.request))); | ||
}); | ||
|
||
self.addEventListener('message', (event) => { | ||
if (event.data.action === 'skipWaiting') { | ||
self.skipWaiting(); | ||
} | ||
}); |