Removing raw HTML

This commit is contained in:
Brandon Rozek 2025-02-16 22:04:56 -05:00
parent e06d45e053
commit 572d587b8e
No known key found for this signature in database
GPG key ID: DFB0E78F805F4567
33 changed files with 373 additions and 386 deletions

View file

@ -62,7 +62,7 @@ var offlineFundamentals = [
```
Since <code class="language-javascript">cache.addAll()</code> hasnt been implemented yet in any of the browsers, and the polyfill implementation didnt work for my needs. I pieced together my own.
Since `cache.addAll()` hasnt been implemented yet in any of the browsers, and the polyfill implementation didnt work for my needs. I pieced together my own.
```javascript
var updateStaticCache = function() {
@ -85,8 +85,8 @@ var updateStaticCache = function() {
Lets go through this chunk of code.
1. Open the cache called <code class="language-javascript">'v2.0.24:fundamentals'</code>
2. Go through all of the <code class="language-javascript">offlineFundamental</code>s URLs
1. Open the cache called `'v2.0.24:fundamentals'`
2. Go through all of the `offlineFundamental`s URLs
* Does the file I ask for come from the same domain as my site?
* No. Then, make the request no-cors (I had difficulty getting my asset files in cors mode. If the cors headers are included in the response, then you can take out this line)
* Fetch the file from the network and then cache it.
@ -140,7 +140,7 @@ self.addEventListener("activate", function(event) {
The cool thing about service workers is that it can handle file requests. We could cache all files requested for offline use, and if a fetch for a resource failed, then the service worker can look for it in the cache or provide an alternative. This is a large section, so Im going to attempt to break it down as much as I can.
## Limit the cache {#limit-the-cache}
## Limit the cache
If the visitor started browsing all of the pages on my site, his or her cache would start to get bloated with files. To not burden my visitors, I decided to only keep the latest 25 pages and latest 10 images in the cache.
@ -159,7 +159,7 @@ Well call it later in the code.
## Fetch from network and cache
Every time I fetch a file from the network I throw it into a specific cache container. <code class="language-javascript">'pages'</code> for HTML files, <code class="language-javascript">'images'</code> for CSS files, and <code class="language-javascript">'assets'</code> for any other file. This is so I can handle the cache limiting above easier. Defined within the `fetch` event.
Every time I fetch a file from the network I throw it into a specific cache container: `'pages'` for HTML files, `'images'` for CSS files, and `'assets'` for any other file. This is so I can handle the cache limiting above easier. Defined within the `fetch` event.
```javascript
var fetchFromNetwork = function(response) {
@ -371,4 +371,4 @@ self.addEventListener("fetch", function(event) {
self.addEventListener("activate", function(event) {
event.waitUntil(clearOldCaches())
});
```
```