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é
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.