You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
A "replacer" is a reducer which is called with the page content and
returns the page content. A replacer can:
- alter the base href for certain user-agents
- replace text in the body template
- omitting script when a header is set
- etc.
For example, omitting javascript for Internet Explorer:
```js
// handler before sapper middleware
(req, res, next) => {
if (req.get('user-agent').toLowerCase().includes("msie")) {
res.replacers = res.replacers || []
res.replacers.push((ctx) => (ctx.script = "", ctx))
}
next()
}
```
or inserting a footer notice on unsupported browsers:
```js
(req, res, next) => {
// matchesUA: https://github.com/browserslist/browserslist-useragent
if (!matchesUA(req.get('user-agent'))) {
res.replacers = res.replacers || []
res.replacers.push((ctx) => (ctx.body.replace(/<\/body>/, `${unsupportedBrowserNotice}</body>`), ctx))
}
next()
}
```
Replacers are run in the order they are defined. System replacers will
run last in order:
→ base href
→ head
→ styles
→ html
→ script.
0 commit comments