Skip to content

Commit 3ccedb7

Browse files
committed
Merge remote-tracking branch 'origin/master' into development
2 parents e28d5f6 + b3e4b77 commit 3ccedb7

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ $ npm run dev
2222

2323
If port 8080 is already in use on your machine you must change the port number in `/config/index.js`. Otherwise `npm run dev` will fail.
2424

25+
## What's not Included
26+
27+
* You should configure your web server to add HTTP headers to prevent caching of critical service worker files.
28+
If you don't do this, [browsers might cache the content for up to 24 hours](https://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours/38854905#38854905).
29+
In addition, you should add HTTP headers to prevent the contents of the static folder to be cached unintentionally long.
30+
31+
See ["Configuring your Web server to prevent caching"](docs/prevent_caching.md) in the docs for more information.
32+
2533
## What's Included
2634

2735
* Service Worker precaching of application shell + static assets (prod)
@@ -63,3 +71,13 @@ You can fork this repo to create your own boilerplate, and use it with `vue-cli`
6371
```bash
6472
vue init username/repo my-project
6573
```
74+
75+
## Contributing
76+
77+
This project is a modified copy of the [`vue-webpack-boilerplate`](https://github.com/vuejs-templates/webpack) template.
78+
79+
While we welcome contributions from the community, please note that changes to configuration that is shared between this project and `vue-webpack-boilerplate` should be made against `vue-webpack-boilerplate` *first*.
80+
81+
Once the [upstream](https://stackoverflow.com/a/2739476/385997) PR is merged, please file an additional PR against this project making the equivalent changes. This will help ensure that the shared configuration does not diverge too much.
82+
83+
Any changes that are specific to this project—related to service workers, or other PWA functionality—do not need an equivalent upstream PR.

docs/prevent_caching.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Configuring your Web server to prevent caching
2+
3+
## Why you want to do this
4+
5+
You should configure your web server to add HTTP headers to prevent caching of critical service worker files.
6+
If you don't do this, [browsers might cache the content for up to 24 hours](https://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours/38854905#38854905).
7+
8+
In addition, you should add HTTP headers to prevent the contents of the static folder to be cached unintentionally long.
9+
10+
## Mechanisms at work
11+
12+
### Service worker
13+
14+
When you run the production build and deploy the application to a web server, the browser will call the service worker on the first visit and will download and cache all resources.
15+
When the browser accesses the site a second time, it will use the cached resources.
16+
To notice changes in your app it is crucial that the browser downloads the latest version `service-worker.js` from your server.
17+
The browser will only do this when the [Cache-Control](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching) header associated with `service-worker.js` indicates that a previous download has expired or [24 hours have passed](https://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours/38854905#38854905).
18+
If a new service worker is available, it will download the new contents in the background.
19+
Once the download is complete, the default behavior is that the new content will be shown on the next visit of the site.
20+
You can change the template's [`service-worker-prod.js`](../template/build/service-worker-prod.js) to display the message to the user to reload the page, or issue a `window.location.reload()` automatically to trigger an update depending on your application's needs.
21+
22+
Depending on your setup, you might want to have a short caching time for your service worker or no caching at all.
23+
At minimum, you should add caching headers to disable or minimize caching for `service-worker.js` and `index.html`.
24+
25+
### The static folder
26+
27+
The folder [`static`](../template/static) contains the manifest and the favicons of your app.
28+
29+
You should limit or disable caching for all files in this folder to ensure users have receive the latest version of these files.
30+
31+
### Additional information
32+
33+
More information about caching headers can be found in the blog post ["Caching best practices & max-age gotchas" by Jake Archibald](https://jakearchibald.com/2016/caching-best-practices/).
34+
35+
## How to add caching headers for your server
36+
37+
Here are some examples that worked for other users of this template.
38+
See [Issue #70](https://github.com/vuejs-templates/pwa/issues/70) for a discussion.
39+
40+
Apache: Disable all caching for the two essential files
41+
42+
<Files index.html|service-worker.js>
43+
FileETag None
44+
Header unset ETag
45+
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
46+
Header set Pragma "no-cache"
47+
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
48+
</Files>
49+
50+
Apache: Limit caching to five minutes to all files to prevent unlimited caching also for files in static
51+
52+
Header set Cache-Control "max-age=300, must-revalidate"
53+
54+
Nginx: Limit caching for the two essential files
55+
56+
location ~ (index.html|service-worker.js)$ {
57+
# ...
58+
add_header Last-Modified $date_gmt;
59+
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
60+
if_modified_since off;
61+
expires off;
62+
etag off;
63+
}

0 commit comments

Comments
 (0)