Skip to content

Optionally loading the PWA-INSTALL #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rharsh opened this issue Dec 13, 2024 · 1 comment
Open

Optionally loading the PWA-INSTALL #110

rharsh opened this issue Dec 13, 2024 · 1 comment
Labels
question Further information is requested

Comments

@rharsh
Copy link

rharsh commented Dec 13, 2024

Hi @khmyznikov

Just a suggestion. In a regular PWA - I am writing this code in the HTML-HEAD Script tag. Mainly to avoid loading the bundle again after the PWA is install (reducing server load).

I am just checking display-mode: standalone, may be a better method exists. So the entire script is available only if the APP is not installed. Anyway great work on automating the INSTALL process in a much nicer way. Anyway tried it on the demo and its working as expected.

@khmyznikov - your comments much appreciated. (Especially on the method and its usage - any downside ?)

<script>
	if(window.matchMedia('(display-mode: standalone)').matches) {
		console.log("INSTALL JS Not required - not loaded");
		// do not do it
	} else {
		console.log("Loading JS")
		let scriptEle = document.createElement("script");
		scriptEle.setAttribute("src", "./pwa-install.bundle.js");
		scriptEle.setAttribute("type", "module");
		document.head.appendChild(scriptEle);
		scriptEle.addEventListener("load", () => {
			console.log("Installer Script File loaded")
		});
		scriptEle.addEventListener("error", (ev) => {
			console.log("Error : Installer Script File Not Loaded", ev);
		});
	}	
</script>
@khmyznikov khmyznikov added the question Further information is requested label Dec 18, 2024
@khmyznikov
Copy link
Owner

Yeah I think your approach should work. I can only suggest to try to play with:
<script type="module"> import "./pwa-install.bundle.js"; </script>
https://www.w3schools.com/js/js_modules.asp

But I'm not sure it will work right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants