Coder Social home page Coder Social logo

leovolpatto / offline_pwa Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 11 KB

Simple example of working PWA caching static assets and API request even in Safari (>=11.3)

License: MIT License

CSS 2.44% JavaScript 73.84% HTML 23.72%
pwa safari ios offline

offline_pwa's Introduction

offline_pwa

Simple example of working PWA caching static assets and API request even in Safari (>=11.3) This service worker solves an issue with Safari ERR_NETWORK_DISCONNECTED error that happens when you go offline Basically, on each fectch event the sw does the following:

1 - Check whether the requested url is an API endpoint

1.1 - It is not an API endpoint but static asset

1.1.1 - Open the cache and look for the asset

1.1.2 - If the asset is not cached then try to retrieve it from the network

1.1.2.1 - If navigator is online, fetches the url (this if statement is needed to handle Safari offline fetch error)

1.1.2.2 - If navigator is offline then tries to fetch the url from the cache.

1.1.2.3 - If the asset is not in cache, returns an empty respose 200

1.2 - It is an API endpoint

1.2.1 - If navigator is online, fetches the url (this if statement is needed to handle Safari offline fetch error)

1.2.2 - If navigator is offline then tries to fetch the url from the cache.

1.2.3 - If the asset is not in cache, returns an empty respose 200

1.2.4 - If the response was not ok throws an error to be catched and then fetched from cache

1.2.5 - If it was not an error and it was a GET request, caches the request response

It was just an quick example. Feel free to suggest refactorings. [email protected]

offline_pwa's People

Contributors

leovolpatto avatar

Watchers

James Cloos avatar  avatar

Forkers

scriptfarm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.