[PWA] 11. Serve Skeleton Cache for Root

Source: Internet
Author: User

Intead of Cache The root floder, we want to cache skeleton instead.

 self.addeventlistener (' Install ', function   function   return  
     
       Cache.addall ([
      '/ ' js/main.js '  ' css/main.css ' ,  ' imgs/icon.png ' ,  ' https://fonts.gstatic.com/s /roboto/v15/2ux7wltfw3w8tcltuvlfyq.woff ' ,  ' https://fonts.gstatic.com/s        /roboto/v15/d-6iyplofoccackzxwxsod8e0i7kzn-epnyo3hzu7kw.woff ' 

Respond to requests for the root page with thepage skeleton from the cache:

Self.addeventlistener (' Fetch ',function(event) {    //Use the page skeleton from the cacheLet Requesturl =NewURL (Event.request.url); if(Requesturl.origin = = =Location.origin) {        if(Requesturl.pathname = = = '/')) {Event.respondwith (Caches.match ('/skeleton ')            ); return; }} event.respondwith (Caches.match (event.request). Then (function(response) {returnResponse | |fetch (event.request); })    );});

[PWA] 11. Serve Skeleton Cache for Root

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.