How do I set the start_url of a manifest.json to be the root of the site?

Keith picture Keith · Jul 31, 2017 · Viewed 28k times · Source

I have a manifest.json and it has a start_url property that I want to point to the first file of my single page application.

This is index.html, and it's the root of the site. I want this to be the start_url, but that file is never asked for as a URL.

How do I point start_url at the relative root of the site?

For instance, suppose the site is at https://example.com, what should the value of start_url be in https://example.com/manifest.json? I want the PWA to start at https://example.com and not https://example.com/index.html. The PWA might be put on a different domain, so start_url needs to be relative, not absolute.

Answer

Keith picture Keith · May 14, 2019

If you are running in the root of a site, for instance https://example.com/manifest.json or https://test.example.com/manifest.json you can use "start_url": "/".

However, this will also map https://example.com/test/manifest.json to https://example.com/, which fails because it's in a folder outside the scope of the manifest.

Instead, if you are using a sub-directory you need to set both a scope and the start_url:

"start_url": "./"
"scope": "."

This will cause https://example.com/test/manifest.json to map to https://example.com/test/ as expected.