Skip to content

Commit 6fb749c

Browse files
author
patched.codes[bot]
committed
Patched /Users/user/Documents/GitHub/example-python/sw.js
1 parent e24fb58 commit 6fb749c

File tree

1 file changed

+93
-67
lines changed

1 file changed

+93
-67
lines changed

sw.js

Lines changed: 93 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,93 @@
1-
2-
if (location.href.includes('howdz.xyz')) {
3-
importScripts('https://cdn.staticfile.org/workbox-sw/7.0.0/workbox-sw.js')
4-
workbox.setConfig({
5-
debug: false,
6-
});
7-
console.log('sw.js is load by CDN!')
8-
} else {
9-
importScripts('./workbox/workbox-sw.js')
10-
workbox.setConfig({
11-
debug: false,
12-
modulePathPrefix: './workbox/'
13-
});
14-
console.log('sw.js is load by local!')
15-
}
16-
17-
// Cache css/js/font.
18-
workbox.routing.registerRoute(
19-
({ request }) => request.destination === 'style' || request.destination === 'script' || request.destination === 'font',
20-
new workbox.strategies.CacheFirst({
21-
cacheName: 'css-js-font',
22-
plugins: [
23-
new workbox.cacheableResponse.CacheableResponsePlugin({
24-
statuses: [200],
25-
}),
26-
new workbox.expiration.ExpirationPlugin({
27-
maxEntries: 50,
28-
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
29-
}),
30-
]
31-
})
32-
);
33-
34-
// Cache image.
35-
workbox.routing.registerRoute(
36-
({ request }) => request.destination === 'image',
37-
new workbox.strategies.StaleWhileRevalidate({
38-
cacheName: 'image',
39-
plugins: [
40-
new workbox.cacheableResponse.CacheableResponsePlugin({
41-
statuses: [200],
42-
}),
43-
new workbox.expiration.ExpirationPlugin({
44-
maxEntries: 50,
45-
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
46-
})
47-
]
48-
})
49-
)
50-
51-
// Cache video
52-
workbox.routing.registerRoute(
53-
({ request }) => request.destination === 'video',
54-
new workbox.strategies.CacheFirst({
55-
cacheName: 'video',
56-
plugins: [
57-
new workbox.cacheableResponse.CacheableResponsePlugin({
58-
statuses: [200],
59-
}),
60-
new workbox.expiration.ExpirationPlugin({
61-
maxEntries: 50,
62-
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
63-
}),
64-
new workbox.rangeRequests.RangeRequestsPlugin()
65-
]
66-
})
67-
)
1+
2+
if (location.href.includes('howdz.xyz')) {
3+
importScripts('https://cdn.staticfile.org/workbox-sw/7.0.0/workbox-sw.js')
4+
workbox.setConfig({
5+
debug: false,
6+
});
7+
console.log('sw.js is load by CDN!')
8+
} else {
9+
importScripts('./workbox/workbox-sw.js')
10+
workbox.setConfig({
11+
debug: false,
12+
modulePathPrefix: './workbox/'
13+
});
14+
console.log('sw.js is load by local!')
15+
}
16+
17+
// Cache css/js/font.
18+
workbox.routing.registerRoute(
19+
/**
20+
* Method that checks if a request's destination is either 'style', 'script' or 'font'.
21+
* @param {Object} request - The request object.
22+
* @returns {Boolean} True if the request's destination is either 'style', 'script', or 'font', and False otherwise.
23+
*/
24+
```
25+
26+
Code:
27+
```javascript
28+
({ request }) => request.destination === 'style' || request.destination === 'script' || request.destination === 'font',
29+
({ request }) => request.destination === 'style' || request.destination === 'script' || request.destination === 'font',
30+
new workbox.strategies.CacheFirst({
31+
cacheName: 'css-js-font',
32+
plugins: [
33+
new workbox.cacheableResponse.CacheableResponsePlugin({
34+
statuses: [200],
35+
}),
36+
new workbox.expiration.ExpirationPlugin({
37+
maxEntries: 50,
38+
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
39+
}),
40+
]
41+
})
42+
);
43+
44+
// Cache image.
45+
workbox.routing.registerRoute(
46+
/**
47+
* Checks if the request destination is an image
48+
* @param {Object} request - The request object
49+
* @returns {Boolean} Returns true if the request destination is 'image', otherwise returns false
50+
*/
51+
52+
({ request }) => request.destination === 'image',
53+
({ request }) => request.destination === 'image',
54+
new workbox.strategies.StaleWhileRevalidate({
55+
cacheName: 'image',
56+
plugins: [
57+
new workbox.cacheableResponse.CacheableResponsePlugin({
58+
statuses: [200],
59+
}),
60+
new workbox.expiration.ExpirationPlugin({
61+
maxEntries: 50,
62+
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
63+
})
64+
]
65+
})
66+
)
67+
68+
// Cache video
69+
workbox.routing.registerRoute(
70+
/**
71+
* This is a higher-order function that checks if the destination of a given request is 'video'.
72+
* @param {Object} request - An object that contains information about the HTTP request.
73+
* @returns {boolean} Returns true if the destination of the request is 'video', false otherwise.
74+
*/
75+
```
76+
Code:
77+
```javascript
78+
({ request }) => request.destination === 'video',
79+
({ request }) => request.destination === 'video',
80+
new workbox.strategies.CacheFirst({
81+
cacheName: 'video',
82+
plugins: [
83+
new workbox.cacheableResponse.CacheableResponsePlugin({
84+
statuses: [200],
85+
}),
86+
new workbox.expiration.ExpirationPlugin({
87+
maxEntries: 50,
88+
maxAgeSeconds: 60 * 60 * 24 * 7, // 7 Days
89+
}),
90+
new workbox.rangeRequests.RangeRequestsPlugin()
91+
]
92+
})
93+
)

0 commit comments

Comments
 (0)