swarup
swarup

Reputation: 159

can index html and service worker js files be placed in different folder

I placed my files as

where I wants to cache the index.js and mycss.css file which is not working. And due to some constraint, I can't put the service-worker.js in parallel to index.html page

Upvotes: 2

Views: 746

Answers (3)

Niladri Basu
Niladri Basu

Reputation: 10614

Absolutely yes. Moreover, it is considered to be a standard practice to place similar/related files in their respective folder.

So, in your index.html you could do something like this:

<body>
<script src="/files/mycss.css"></script>
<script src="/files/index.js"></script>
<script src="/files/service-worker.js"></script>
</body>

Upvotes: 2

Dushyant Sabharwal
Dushyant Sabharwal

Reputation: 355

Another approach of solving the problem is to set the Service-Worker-Allowed HTTP response header if the scope of service-worker.js is different from the scope of files it wants to work with. This idea helps in applications where URL rewriting is done or the context path for files is not similar to the actual directory structure.

Upvotes: 2

Vasi
Vasi

Reputation: 25

Yes you can put your files in different folders. When you want to "connect" your css to the html the path is:

src="files/mycss.css"

Hope this will help you.

Upvotes: 1

Related Questions