Adds loading and caching optimizations to HTML5 web games exported from Defold.
- Minifies HTML and JS to reduce file size and speed loading
- Adds preload meta tags to speed up first boot
- Generates a service worker to persistently cache assets
-
Install Nodejs or equivalent
-
Clone this project (or fork it in Github)
git clone https://github.com/thinknathan/def-html5-opt
-
Install dependencies
npm i
oryarn
- Build your HTML5 export from Defold
- Copy your game files into the
copy-game-here
folder (don't include the build report: excludereport.html
and similar)
You can skip any of the following steps you don't want to run. This is the recommended order:
- Run
yarn preload
ornpm run preload
to add preload meta tags - Run
yarn minify
ornpm run minify
to reduce the size ofindex.html
anddmloader.js
- Run
yarn sw
ornpm run sw
to generate the service worker
Done! We've completed the modifications to your game in the copy-game-here
folder.
Upload all the files inside copy-game-here
to distribute your game.
Since Defold's usage of emscripten
lags behind the latest release, you may be able to gain an improvement to speed and/or file size by downloading the latest version of wasm-opt and running it on your wasm binary.