-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from NekR/v4.9.0
V4.9.0
- Loading branch information
Showing
92 changed files
with
6,837 additions
and
480 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
node_modules/ | ||
__output/ | ||
/__* | ||
.DS_Store | ||
.idea | ||
.idea | ||
npm-debug.log |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "6" | ||
- "5" | ||
- "4" | ||
- "8" | ||
- "9" | ||
env: | ||
- TEST_METHOD=ci_fixtures | ||
matrix: | ||
include: | ||
- node_js: "8" | ||
env: TEST_METHOD=ci_all | ||
script: npm run test:"$TEST_METHOD" |
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,18 @@ | ||
# `appShell: string` | ||
|
||
> Default: `null`. | ||
> **Example:** `'/'` | ||
When making a Singe Page Application, it's common to use [AppShell](https://medium.com/google-developers/instant-loading-web-apps-with-an-application-shell-architecture-7c0c2f10c73) model for it. | ||
|
||
To make `offline-plugin` redirect all unknown navigation requests to a specific cache, specify `appShell` option, e.g. `appShell: '/'`. | ||
|
||
### SSR | ||
|
||
When using Server Side Rendering with AppShell model, make sure that you do not cache any server rendered data with it. Easiest way would be to make a route which will be serving the HTML file without any server rendered data in it (e.g. ready for client side rendering) and cache that route. Example: `appShell: '/app-shell.html'` | ||
|
||
### Advanced | ||
|
||
Previously, to achieve the same effect, `ServiceWorker.navigateFallbackURL` and `AppCache.FALLBACK` option had to be used. `ServiceWorker.navigateFallbackURL` is now deprecated and shouldn't be used at all. Instead, `appShell` should be used. | ||
|
||
`appShell` is baked by `cacheMaps` option for `ServiceWorker` and `AppCache.FALLBACK` option for `AppCache`. |
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,76 @@ | ||
## `navigationPreload: boolean | Object | ':auto:'` | ||
> _Default:_ `':auto:'` | ||
[Navigation preload](https://developers.google.com/web/updates/2017/02/navigation-preload) is a ServiceWorker's feature which provides a way to make a request to the website even before ServiceWorker or a page is initialized. This can be useful for data fetching to speedup loading of the application. | ||
|
||
### Usage | ||
|
||
In `offline-plugin`, _Navigation preload_ behaves differently for `cache-first` and `network-first` response strategies. | ||
|
||
For `network-first` navigation preload is enabled by default and allows to fetch navigation pages ahead of time, even before ServiceWorker was initialized. To disabled it set `ServiceWorker.navigationPreload` option to `false`. | ||
|
||
For `cache-first` navigation preload has to be enabled manually and also handled on the server side. To enabled navigation preload two functions has to be specified: | ||
|
||
```js | ||
ServiceWorker: { | ||
navigationPreload: { | ||
map: (url) => { | ||
if (url.pathname === '/') { | ||
return '/api/feed'; | ||
} | ||
|
||
var post = url.pathname.match(/^\/post\/(\d+)$/); | ||
|
||
if (post) { | ||
return '/api/post/' + post[1]; | ||
} | ||
}, | ||
test: (url) => { | ||
if (url.pathname.indexOf('/api/') === 0) { | ||
return true; | ||
} | ||
} | ||
}, | ||
} | ||
``` | ||
|
||
* `map` function is used to map navigation preload request to other requests, e.g. API requests. | ||
* `test` function is used to test for possible consumers of navigation preload mapping | ||
|
||
In previous example `map` function maps navigation preload of `/` to `/api/feed`. Then when a request to `/api/feed` happens, `test` function is used to determine that such request might be preloaded with _navigation preload_ (it checks if `pathname` of the request starts with `/api/`). | ||
|
||
#### Server Side | ||
|
||
When a navigation preload request happens, it contains `Service-Worker-Navigation-Preload: true` header. Server side should use this header to detect the preload and send different content to such request. | ||
|
||
Express.js example: | ||
|
||
```js | ||
function serveIndex(req, res) { | ||
if (req.headers['service-worker-navigation-preload']) { | ||
res.set({ | ||
'Cache-Control': 'no-cache', | ||
'Vary': 'Service-Worker-Navigation-Preload' | ||
}); | ||
|
||
fetchFeedData(req).then((data) => { | ||
res.send(data); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
res.sendFile(path.join(WWW_FOLDER, 'index.html'), { | ||
cacheControl: false, | ||
acceptRanges: false, | ||
headers: { | ||
'Cache-Control': 'no-cache', | ||
'Vary': 'Service-Worker-Navigation-Preload' | ||
} | ||
}); | ||
} | ||
``` | ||
|
||
Make sure to set **`'Vary': 'Service-Worker-Navigation-Preload'`** header if you're planning on caching those responses. | ||
|
||
For more details on Navigation Preload see [this article](https://developers.google.com/web/updates/2017/02/navigation-preload). |
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
Oops, something went wrong.