How to Setup Your Web App Manifest Dynamically Using Javascript

Omar Alshaker

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade