Skip to content

Commit

Permalink
ServiceWorker / Workbox Tweaks (#826)
Browse files Browse the repository at this point in the history
* Update sw.js

* Only precache the index HTML.
  • Loading branch information
developit authored and prateekbh committed Jul 16, 2019
1 parent c89fe14 commit 10c2dfb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/cli/lib/lib/sw.js
Expand Up @@ -9,8 +9,8 @@ self.__precacheManifest = [].concat(self.__precacheManifest || []);
if (process.env.ENABLE_BROTLI && process.env.ES_BUILD) {
// Alter the precache manifest to precache brotli files instead of gzip files.
self.__precacheManifest = self.__precacheManifest.map(asset => {
if (/.*.js$/.test(asset.url)) {
asset.url = asset.url.replace(/.esm.js$/, '.esm.js.br');
if (/\.js$/.test(asset.url)) {
asset.url = asset.url.replace(/\.esm\.js$/, '.esm.js.br');
}
return asset;
});
Expand All @@ -19,7 +19,7 @@ if (process.env.ENABLE_BROTLI && process.env.ES_BUILD) {
// Before saving the response in cache, we need to treat the headers.
async cacheWillUpdate({ response }) {
const clonedResponse = response.clone();
if (/.js.br(\?.*)?$/.test(clonedResponse.url)) {
if (/\.js\.br(\?.*)?$/.test(clonedResponse.url)) {
const headers = new Headers(clonedResponse.headers);
headers.set('content-type', 'application/javascript');
return new Response(await clonedResponse.text(), { headers });
Expand All @@ -33,8 +33,8 @@ if (process.env.ENABLE_BROTLI && process.env.ES_BUILD) {
const precacheOptions = {};
if (process.env.ENABLE_BROTLI) {
precacheOptions['urlManipulation'] = ({ url }) => {
if (/.esm.js$/.test(url.href)) {
url.href = url.href + '.br';
if (/\.esm\.js$/.test(url.href)) {
url.href += '.br';
}
return [url];
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/lib/webpack/webpack-client-config.js
Expand Up @@ -260,7 +260,7 @@ function isProd(config) {
prodConfig.plugins.push(
new InjectManifest({
swSrc: 'sw-esm.js',
include: [/index\.html$/, /\.esm.js$/, /\.css$/, /\.(png|jpg)$/],
include: [/^\/?index\.html$/, /\.esm.js$/, /\.css$/, /\.(png|jpg)$/],
precacheManifestFilename: 'precache-manifest.[manifestHash].esm.js',
})
);
Expand Down

0 comments on commit 10c2dfb

Please sign in to comment.