简体   繁体   中英

Is a service worker cache faster than http cache?

The test page has static JavaScript, CSS, images, etc. which are stored in a CDN with cache-control max-age set to about 5 years. We collect load events for the user to open the page and the average is about 1.9s. When I add a service worker cache and have it only cache the JavaScript, CSS, and images, the average load time is about 1.6s.

Why can a service worker cache reduce the page load time?

Service worker can cache html files. Storing html files in a http cache is not a good idea (because there'd be virtually no way to update your site before cache expiration date)

also if you use etags/If-None-Match , the request is sent to check if the file changed before it is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM