YoYo Honey Singh
YoYo Honey Singh

Reputation: 464

how to add service workers in my existing php website

I’m trying to add service wrokers in my existing php mobile site.So i want to know what is the best way to do that(like design pattern). I can cache all my static assets like css,js.But how to cache actual html contents that are not chaging rapidly.I know that i can cache based on network requests. But how to cache different units of main view because it has only one request.

Upvotes: 0

Views: 11464

Answers (2)

Salva
Salva

Reputation: 6847

If I understand correctly, I think you want to only cache specific parts of the same HTML. That's not directly supported but you can use diffs to only download the differences between the old and new HTML files. I strongly recommend you to take a look at sw-delta.

You can refer to the Offline Cookbook by Jake Archibald and caching strategies examples in the Service Worker Cookbook also. Both include recommendations for when to use specific strategies.

Upvotes: 1

Kevin Farrugia
Kevin Farrugia

Reputation: 7449

You are able to cache by URL, so you are able to cache "/" if that is your root URL. It will cache the HTTP response, so ultimately it is irrelevant what this is made up of (including whether this is PHP or .NET).

Having said that, if the content on the page changes you will need to invalidate the cache when it has changed and retrieve the latest content so it might not be a suitable candidate for caching.

From the bit of experience in building offline apps I cache static assets (HTML templates, CSS & JS) and then store data from API responses in IndexedDB. This allows me to have an offline app-shell (from CacheAPI) & the latest version of the retrieved data (IndexedDB) and when the user is connected I can refresh/update the IndexedDB content.

Read more: https://medium.com/@addyosmani/offline-storage-for-progressive-web-apps-70d52695513c

Upvotes: 2

Related Questions