Skip to content

Commit 9664ea7

Browse files
hopefully finalize
1 parent f84b2df commit 9664ea7

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

README.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,6 +3852,7 @@ h1 {
38523852
[^104]:[CodeSandbox: HTML Performance Optimization Techniques.](https://qm3w7j.csb.app/), last access: September 10, 2024.
38533853

38543854
- In this example, the `<link rel="preload">` tag is used to prioritize the loading of critical resources (CSS and JavaScript files) by indicating their importance and specifying the `as` attribute to define the resource type.
3855+
- **There is a problem with this example in CodeSandbox environment to get it fully working, it's just for your information how it should work, sorry for that. Follow https://github.com/codesandbox/codesandbox-client/issues/8610 for more information.**
38553856

38563857
##### Code Example: HTML Minification and Compression
38573858

@@ -4296,22 +4297,20 @@ registerServiceWorker();
42964297
##### Example: Caching Assets for Offline Use
42974298

42984299
```javascript
4299-
const CACHE_NAME = 'my-site-cache-v1';
4300-
const urlsToCache = [
4301-
"index.html",
4302-
"./", // Alias for index.html
4303-
"styles.css",
4304-
"script.js",
4305-
"example.png",
4306-
];
4307-
4308-
self.addEventListener('install', function(event) {
4300+
const addResourcesToCache = async (resources) => {
4301+
const cache = await caches.open("v1");
4302+
await cache.addAll(resources);
4303+
};
4304+
4305+
self.addEventListener("install", (event) => {
43094306
event.waitUntil(
4310-
caches.open(CACHE_NAME)
4311-
.then(function(cache) {
4312-
alert('Cache opened');
4313-
return cache.addAll(urlsToCache);
4314-
})
4307+
addResourcesToCache([
4308+
"/",
4309+
"/index.html",
4310+
"/style.css",
4311+
"/script.js",
4312+
"/example.png",
4313+
])
43154314
);
43164315
});
43174316
```
@@ -4337,10 +4336,9 @@ h1 {
43374336
[^119]:[CodeSandbox: Caching Assets for Offline Use.](https://tmpq6w.csb.app/), last access: October 11, 2024.
43384337

43394338
- The code above demonstrates how to cache assets for offline use using a Service Worker.
4340-
- During the Service Worker installation phase (`install` event), it opens a cache named `my-site-cache-v1`.
4341-
- It then adds specified URLs (including HTML, CSS, JavaScript, and image files) to the cache using the `addAll()` method.
4339+
- During the Service Worker installation phase (`install` event), it opens a cache named `v1`.
4340+
- It then adds specified URLs (including HTML, CSS, JavaScript, and image files) to the cache using the `addAll()` method, embedded in `addResourcesToCache()`.
43424341
- The cached assets can be served from the cache when the user is offline, providing offline access to the application.
4343-
- **There is a problem with this example in CodeSandbox environment to get it fully working, it's just for your information how it should work, sorry for that.**
43444342

43454343
##### Example: Offline Data Synchronization
43464344

0 commit comments

Comments
 (0)