Bhupesh-V / tutorialdb

A search 🔎 engine for programming/dev tutorials,
MIT License
121 stars 60 forks source link

Fix PWA #67

Closed viktorstrate closed 4 years ago

viktorstrate commented 4 years ago

This pull request, resolves #36

Screenshot 2019-10-14 at 22 07 38

Lighthouse result

Screenshot 2019-10-14 at 22 06 50
Animesh-Ghosh commented 4 years ago

Hey man, you need to follow the Django file structure conventions.

viktorstrate commented 4 years ago

Are you refering to the service-worker.js not being located under /static/? If not please correct me.

I needed to move the service worker to the root, otherwise it can only be used for files under the /static/ subdirectory. This has to do with the scope of service workers, and this was acually the reason why it didn't work before.

See Google's Introduction to Service Worker - Registration and Scope

The scope of the service worker determines which files the service worker controls, in other words, from which path the service worker will intercept requests. The default scope is the location of the service worker file, and extends to all directories below. So if service-worker.js is located in the root directory, the service worker will control requests from all files at this domain.

Because of this it is the standard to always have the service worker at the root of the site.

It is possible to have a service worker, under a subdirectory, control the root of the site, but a HTTP header would have to be set by the server to allow this, as this can be a security problem. See Service-Worker-Allowed HTTP Header

Edit: See this Stack Overflow question for service workers in Django https://stackoverflow.com/questions/38696595/django-and-service-workers-serve-sw-js-at-applications-root-url

Bhupesh-V commented 4 years ago

I guess we need to test it first. The PR looks :fire: But can you apply few changes.

viktorstrate commented 4 years ago

I've changed name and logo in the latest commit

Bhupesh-V commented 4 years ago

@viktorstrate Thanks for your contributions :tada: , the changes will be live soon. Sorry for the late merge :crying_cat_face:

Bhupesh-V commented 4 years ago

@all-contributors please add @viktorstrate for code

allcontributors[bot] commented 4 years ago

@Bhupesh-V

I've put up a pull request to add @viktorstrate! :tada: