How to Setup Your Web App Manifest Dynamically Using Javascript

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.

--

--

Frontend developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store