Easily add a website to your IOS/Android/Desktop homescreen (Demo).
Add to home screen allows websites and PWA's to work like native apps without registering in the Apple or Google App Stores. Currently, it is very difficult to get users to add web apps to their home screen, limiting the utility of such websites compared to native apps. See related Medium blog post.
This drop-in JS Library for websites effectively guides a user to add the website to their home screen on IOS, Android and Desktop.
Instructions and UI in this library have been "battle-tested" and have yielded an ~85% home screen install rate on IOS and Android across all ages in past implementations.
Here is a demo (please open on your phone) of library use within a hypothetical app "Aardvark"
Translated to 20+ languages.
All major browsers with > 10% market share on IOS/Android/Desktop are supported. Here are the guides shown for each platform/browser:
In-App browsers on popular social apps are supported. Users are guided to open the link in the system browser, then the standard add-to-homescreen flow appears.
Apps Supported:
- Instagram (IOS, Android)
- Facebook (IOS, Android)
- X / Twitter (IOS, Android - opens in system browser)
Make sure your website meets the minimum requirements for installing a web app on homescreen for IOS and Android and Desktop.
-
At
https://your-website.com/apple-touch-icon.png, include a square icon of your app that is (1) at least 40 x 40 pixels and (2) specifically namedapple-touch-icon.png(example). -
At
https://your-website.com/manifest.json, include a web manifest filemanifest.json(example). Reference the manifest in your index HTML file.index.html<head> ... <link rel="manifest" crossorigin="use-credentials" href="manifest.json" /> .. </head>
This should be a quick drop-in library into your website.
-
Install the package via npm:
npm install pwa-add-to-homescreen
-
Include the library JavaScript and CSS files in your header from the local
node_modulesdirectory:index.html<head> ... <link rel="stylesheet" href="node_modules/pwa-add-to-homescreen/dist/add-to-homescreen.min.css" /> <script src="node_modules/pwa-add-to-homescreen/dist/add-to-homescreen.min.js"></script> ... </head>
The code above will include a JavaScript file containing all the available translations for the locales this library supports. It is highly optimized to be small and quick to deliver over mobile networks. If however you want to be even more highly optimized, the library also has JavaScript files built with just a single locale of translations, which is about 60% smaller.
For example, the Spanish file
add-to-homescreen_es.min.jscan be included as below. If you have a dynamic server environment and know the user's preferred locale, this can be a good option. To see all the supported locales, look in thedistfolder.<head> <!-- This is the Spanish locale-only version of the library. --> ... <link rel="stylesheet" href="node_modules/pwa-add-to-homescreen/dist/add-to-homescreen.min.css" /> <script src="node_modules/pwa-add-to-homescreen/dist/add-to-homescreen_es.min.js"></script> ... </head>
-
Call the library onload.
index.html<script> document.addEventListener('DOMContentLoaded', function () { window.AddToHomeScreenInstance = window.AddToHomeScreen({ appName: 'Aardvark', // Name of the app. // Required. appNameDisplay: 'standalone', // If set to 'standalone' (the default), the app name will be diplayed // on it's own, beneath the "Install App" header. If set to 'inline', the // app name will be displayed on a single line like "Install MyApp" // Optional. Default 'standalone' appIconUrl: 'apple-touch-icon.png', // App icon link (square, at least 40 x 40 pixels). // Required. assetUrl: 'node_modules/pwa-add-to-homescreen/dist/assets/img/', // Link to directory of library image assets. maxModalDisplayCount: -1, // If set, the modal will only show this many times. // [Optional] Default: -1 (no limit). (Debugging: Use this.clearModalDisplayCount() to reset the count) displayOptions:{ showMobile: true, showDesktop: true }, // show on mobile/desktop [Optional] Default: show everywhere allowClose: true, // allow the user to close the modal by tapping outside of it [Optional. Default: true] showArrow: true, // show the bouncing arrow on the modal [Optional. Default: true] (highly recommend leaving at true as drastically affects install rates) }); ret = window.AddToHomeScreenInstance.show('en'); // show "add-to-homescreen" instructions to user, or do nothing if already added to homescreen // [optional] language. If left blank, then language is auto-decided from (1) URL param locale='..' (e.g. /?locale=es) (2) Browser language settings }); </script> </body>
Here's an example implementation.
3-alternate. if you're calling the UI NOT onload, but sometime after (for example, in an onclick() handler for an "Install App" button), then you should still create your the instance onload, but call your UI later on the instance variable with .show()):
index.html
<script>
document.addEventListener('DOMContentLoaded', function () {
window.AddToHomeScreenInstance = window.AddToHomeScreen({...
}));
document.getElementById('my_install_app_button').addEventListener('click', function () {
window.AddToHomeScreenInstance.show('en');
});
</script>
</body>This is because some handlers must be created onload.
No dependencies. This is written in raw ES6 javascript and all css is namespaced to minimize codebase conflict and bloat.
- Thanks to Shane O'Sullivan for a a massive refactor to improve performance and i18n.


