Preview

What’s included in SitePoint Premium?

A Brief Primer on Service Workers in Django

What’s included in SitePoint Premium?

  • Read offline (beta)
  • 250+ books
  • 120+ courses
  • New content added weekly
  • Ad Free SitePoint
  • Cancel anytime
  • 30 Days Money Back Guarantee!

    Description:

    Adding a service worker to your site—to make it work offline, or to make it a full PWA—can seriously help your users’ experience. A site which works offline isn’t vulnerable to suddenly not working if their train goes into a tunnel, for example. Additionally, there’s less of a concern about your JavaScript not loading, and it can seriously improve your site’s performance and bandwidth usage.

    Your service worker is a JavaScript file which has access to certain privileged functions, and one of the main things it can do is enable your site to work offline by intercepting requests for HTML pages and page dependencies (CSS, JavaScript, images, and so on), and serving cached versions of those pages instead of (or as well as) the versions from the network. Thus, if the user is offline—for extended time, if they’re somewhere without wireless, or temporarily, as they step with their phone into an elevator—your site still works with no interruptions, because the cached versions of your pages are used.

    In this tutorial, Stuart shows you how to add a simple service worker to your Django site, and then moves beyond the basics to show hwo you can achieve background sync.

    available in:

    Reader