How to Setup Your Web App Manifest Dynamically Using Javascript

Omar Alshaker
1 min readJan 16, 2018

--

From a URL or a JSON object

For some reason or another, you might not be able to serve a json file that contains your web app manifest. Maybe you’d like to construct the app manifest on the client side using custom client-selected theme color or icons without involving your server.

In such case, like with document.title, the first thing that comes to one’s mind it to dynamically inject this tag in your document’s head. Like:

But this doesn’t work.

The trick

What I have found to be working, after the genius suggesion from Marcin Warpechowski, is to have a link tag in the HTML with rel="manifest" but without href attribute. And use this tag later to populate your manifest. As in:

Your document:

Now in Javascript you have two options:

  1. Set href attribute using a URL:

2. Use a JSON object to set your manifest

Both ways work.

By this, you can allow your app users to customize the icon, colors, and even the very name of your app without any server involvement.

--

--