Configure your Apache server to allow Service Workers

Trying out Service Workers in your web project, you might have encountered this error message at some point:

The path of the provided scope (‘/’) is not under the max scope allowed (‘/assets/js/’). Adjust the scope, move the Service Worker script, or…


This content originally appeared on DEV Community and was authored by André

Trying out Service Workers in your web project, you might have encountered this error message at some point:

The path of the provided scope ('/') is not under the max scope allowed ('/assets/js/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.

This happens when you try to place your Service Worker (let's call it sw.js) in some folder other than the root folder of your project. While it's basically okay to put that file at root, it might clash with the pattern you had in mind for your project and you'd rather have sw.js in a folder like /assets/js/.

Well, the error message already has all the hints you need to achieve this.

In order to modify the HTTP header, you'll first have to load the headers module in your httpd.conf file by adding/uncommenting this line:
LoadModule headers_module modules/mod_headers.so

Then, assuming your serving via HTTPS, go into your httpd-ssl.conf file and add the following lines:

<IfModule mod_headers.c>
<Files "sw.js">
Header set Service Worker-Allowed "/"
</Files>
</IfModule>

You should now be able to place your Service Worker any place you like inside your project.


This content originally appeared on DEV Community and was authored by André


Print Share Comment Cite Upload Translate Updates
APA

André | Sciencx (2022-07-26T19:57:00+00:00) Configure your Apache server to allow Service Workers. Retrieved from https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/

MLA
" » Configure your Apache server to allow Service Workers." André | Sciencx - Tuesday July 26, 2022, https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/
HARVARD
André | Sciencx Tuesday July 26, 2022 » Configure your Apache server to allow Service Workers., viewed ,<https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/>
VANCOUVER
André | Sciencx - » Configure your Apache server to allow Service Workers. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/
CHICAGO
" » Configure your Apache server to allow Service Workers." André | Sciencx - Accessed . https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/
IEEE
" » Configure your Apache server to allow Service Workers." André | Sciencx [Online]. Available: https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/. [Accessed: ]
rf:citation
» Configure your Apache server to allow Service Workers | André | Sciencx | https://www.scien.cx/2022/07/26/configure-your-apache-server-to-allow-service-workers/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.