Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
PWA - How to cache html pages (not only js, css...)

If I use,

registerRoute(
    new RegExp('.*'),
    new CacheFirst({
        cacheName: 'all',
    })
);

it will work and cache all the pages with all the assets. So if I refresh the page in offline mode, it works.

But apparently it's not a good idea to cache ALL! So I want to cache js|css|eot|ttf|otf|woff|woff2 and of course the html as well.

So if I use

registerRoute(
    new RegExp('(\.(js|css|eot|ttf|otf|woff|woff2)$)'), // <<== how to add html type here to be cached?
    new CacheFirst({
        cacheName: 'all',
    })
);

and refresh the page while it's in offline mode, it can't view the page since it hasn't cached.

I'm using Vuejs, Mix, Workbox.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are a number of different options for configuring runtime routing and caching; you can also create multiple routes with different strategies for each type of resource. Routing based on the request.destination value is a fairly robust approach.

I would avoid using a CacheFirst strategy for any URLs that are unversioned, since you don't have a great way of making sure it ever gets updated after you deploy changes. StaleWhileRevalidate or NetworkFirst is a safer strategy to use for URLs that don't contain hashes.

import {registerRoute} from 'workbox-routing';
import {StaleWhileRevalidate, NetworkFirst} from 'workbox-strategies';

registerRoute(
  // Match HTML document requests.
  ({request}) => request.destination === 'document',
  new NetworkFirst({
    cacheName: 'html',
  })
);

registerRoute(
  // Match JS, CSS, and font requests.
  ({request}) => ['font', 'script', 'style'].includes(request.destination),
  new StaleWhileRevalidate({
    cacheName: 'resources',
  })
);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!