Skip to content

Commit 8ce4444

Browse files
MegginPaulKinlan
authored andcommitted
And now I found out inverse is fix needed for devsite (google#6502)
1 parent 66dea94 commit 8ce4444

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/content/en/tools/workbox/modules/workbox-sw.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ on your own server.
2222
The easiest way to start using this module is via the CDN. You just need to
2323
add the following to your service worker:
2424

25-
```javascript
25+
<pre class="prettyprint js">
2626
importScripts('{% include "web/tools/workbox/_shared/workbox-sw-cdn-url.html" %}');
27-
```
27+
</pre>
2828

2929
With this you’ll have the `workbox` namespace in your service worker that will
3030
provide access to all of the Workbox modules.
3131

32-
```javascript
32+
<pre class="prettyprint js">
3333
workbox.precaching.*
3434
workbox.routing.*
3535
etc
36-
```
36+
</pre>
3737

3838
There is some magic that happens as you start to use the additional modules.
3939

@@ -58,13 +58,13 @@ Release](https://github.com/GoogleChrome/workbox/releases), and then tell
5858

5959
If you put the files under `/third_party/workbox/`, you would use them like so:
6060

61-
```javascript
61+
<pre class="prettyprint js">
6262
importScripts('/third_party/workbox/workbox-sw.js');
6363

6464
workbox.setConfig({
6565
modulePathPrefix: '/third_party/workbox/'
6666
});
67-
```
67+
</pre>
6868

6969
With this, you’ll use only the local Workbox files.
7070

@@ -82,20 +82,20 @@ In order to avoid violating this restriction, a best practice is to reference th
8282

8383
For example, the following top-level service worker code is fine:
8484

85-
```javascript
85+
<pre class="prettyprint js">
8686
importScripts('{% include "web/tools/workbox/_shared/workbox-sw-cdn-url.html" %}');
8787

8888
// This will work!
8989
workbox.routing.registerRoute(
9090
new RegExp('\.png$'),
9191
workbox.strategies.cacheFirst()
9292
);
93-
```
93+
</pre>
9494

9595
But this code could be a problem if you have not referenced `workbox.strategies` elsewhere in your
9696
service worker:
9797

98-
```javascript
98+
<pre class="prettyprint js">
9999
importScripts('{% include "web/tools/workbox/_shared/workbox-sw-cdn-url.html" %}');
100100

101101
self.addEventListener('fetch', (event) => {
@@ -106,13 +106,13 @@ self.addEventListener('fetch', (event) => {
106106
event.respondWith(cacheFirst.makeRequest({request: event.request}));
107107
}
108108
});
109-
```
109+
</pre>
110110

111111
If you need to write code that would otherwise run afoul of this restriction, you can explicitly
112112
trigger the `importScripts()` call outside of the event handler by using the
113113
[`workbox.loadModule()`](/web/tools/workbox/reference-docs/latest/workbox#.loadModule) method:
114114

115-
```javascript
115+
<pre class="prettyprint js">
116116
importScripts('{% include "web/tools/workbox/_shared/workbox-sw-cdn-url.html" %}');
117117

118118
// This will trigger the importScripts() for workbox.strategies and its dependencies:
@@ -125,12 +125,12 @@ self.addEventListener('fetch', (event) => {
125125
event.respondWith(cacheFirst.makeRequest({request: event.request}));
126126
}
127127
});
128-
```
128+
</pre>
129129

130130
Alternatively, you can create a reference to the relevant namespaces outside of your event handlers,
131131
and then use that reference later on:
132132

133-
```javascript
133+
<pre class="prettyprint js">
134134
importScripts('{% include "web/tools/workbox/_shared/workbox-sw-cdn-url.html" %}');
135135

136136
// This will trigger the importScripts() for workbox.strategies and its dependencies:
@@ -143,7 +143,7 @@ self.addEventListener('fetch', (event) => {
143143
event.respondWith(cacheFirst.makeRequest({request: event.request}));
144144
}
145145
});
146-
```
146+
</pre>
147147

148148
Note: Some versions of Chrome do not honor this restriction, and asynchronous calls to
149149
`importScripts()` don't trigger the expected failure. Developers are advised *not* to rely on this
@@ -162,11 +162,11 @@ but for any other origin it’ll use the production build.
162162
If you want to force debug or production builds you set the `debug` config
163163
option.
164164

165-
```javascript
165+
<pre class="prettyprint js">
166166
workbox.setConfig({
167167
debug: <true or false>
168168
});
169-
```
169+
</pre>
170170

171171
## Skip Waiting and Clients Claim
172172

@@ -177,10 +177,10 @@ update and control a web page as soon as possible, skipping the default
177177
If you find yourself wanting this behavior, `workbox-sw` provides some helper
178178
methods to make this easy:
179179

180-
```javascript
180+
<pre class="prettyprint js">
181181
workbox.skipWaiting();
182182
workbox.clientsClaim();
183-
```
183+
</pre>
184184

185185
Note: If your web app lazy-loads resources that are uniquely versioned with, e.g., hashes in their
186186
URLs, it's recommended that you avoid using skip waiting. Enabling it could

0 commit comments

Comments
 (0)