GithubHelp home page GithubHelp logo

Comments (2)

marabesi avatar marabesi commented on June 12, 2024

Registering the service worker is just one part of the puzzle, after that you should modify the serviceworker.js to respond properly.

The file should have the following (as int he Figure 2.8 in the book):

self.addEventListener("fetch", function (event) {
    event.respondWith(
        fetch(event.request).catch(function () {
            return new Response(
                "Welcome to the Gotham Imperial Hotel.\n" +
                "There seems to be a problem with your connection.\n" +
                "We look forward to telling you about our hotel as soon as you go online."
            );
        })
    );
});

from gotham_imperial_hotel.

georgedk4 avatar georgedk4 commented on June 12, 2024

I agree with the original author - the example in chapter two does not work. I am trying to get the offline message to show up in Firefox but even when selecting offline mode, clearing everything out of the browser, unregistering the previously registered service worker, hitting Ctrl-C and then npm start, it still does not show the offline message on my screen. I have also tried to use Chrome in the way outlined in the book and i still cannot see the offline message. Here is my code in "serviceworker.js":-

var responseContent = "<html><body><style>body {text-align: center; background-color: #333; color: #eee;}</style><h1>Gotham Imperial Hotel</h1><p>There seems to be a problem with your connection.</p><p>Come visit us at 1 Imperial Plaza, Gotham City for free WiFi.</p></body></html>"

self.addEventListener("fetch", function(event) { event.respondWith( fetch(event.request).catch(function() { return new Response( responseContent, {headers: {"Content-Type": "text/html"}} ); }) ); });

from gotham_imperial_hotel.

Related Issues (9)

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.