# ResZip: a ready-to-use Lua module and example project on how to use LiveUpdate

**URL:** <https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686>\
**Category:** The Defoldmine\
**Created:** [March 2, 2021, 1:30pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686 "2021-03-02T13:30:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [March 2, 2021, 1:30pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/1 "2021-03-02T13:30:04Z")

</div>

Our publisher asked us to improve the loading time of our game. Their dev has [a good talk](https://vimeo.com/350139974) about its importance for players who run your game for the first time.

Defold packs all the game resources into a large package for the HTML5 platform, and all these files have to be downloaded before startup.

Defold has [the Live Update feature](https://defold.com/manuals/live-update/), which we can use to split resources into two parts: all resources required for the first level of your game plus the rest of resources. The game can load these resources in the background (and from the same folder) while players are playing the first level.

I made an example project that loads resources from a .zip file using Live Update, and you can use it as a Defold library dependency:  
[https://github.com/indiesoftby/defold-liveupdate-reszip](https://github.com/indiesoftby/defold-liveupdate-reszip)

In this project, the demo game loads the level 2 plus required resources from an external .zip file when you tap anywhere on it. I recommend you start loading these extra resources right after your game’s initialisation.

How it looks when implemented in a game:

[https://forum-defold-uploads.b-cdn.net/original/3X/4/5/4521925bb9e1626c2c9240b3415a6021cf1b5cf5.mp4](https://forum-defold-uploads.b-cdn.net/original/3X/4/5/4521925bb9e1626c2c9240b3415a6021cf1b5cf5.mp4)

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [March 2, 2021, 1:36pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/2 "2021-03-02T13:36:37Z")

</div>

Now, about the issues that I faced while implementing this feature.

I didn’t manage to use the `resource.store_archive()` function as is. It loads the whole ZIP archive at once, but it also requires a manifest, and the new manifest requires **a full restart of the game**.

That’s why the demo project calls `resource.store_resource()` just to load resources without a manifest. Moreover, it extracts these resources from a single large ZIP file to avoid slow downloading hundreds of files one by one (I had to use the Miniz library for that).

Another issue is Live Update’s temporary storage of resources in .arcd/.arci files (in IndexedDB). The demo project [deletes these files before the start of the game to handle the upgrade of the game](https://github.com/indiesoftby/defold-liveupdate-reszip/blob/main/liveupdate_reszip/manifests/web/engine_template.html). Otherwise, new resources can have the same filenames but different content. The `collectionproxy.missing_resources` doesn’t know about that, and it loads only new missing resources. The result of this total mess: returning players will not be able to play the game, i.e. it will crash.

To sum up, I would like:

1. To use `resource.store_archive()` to load missing resources from a .zip file and without the new manifest plus without the restart of the game.
2. To be able to disable Live Update’s temporary storage. This case doesn’t need it because a browser already caches all games files, and the game doesn’t use Live Update to upgrade itself.
3. To easily test an HTML5 debug build from IDE without pre-publishing Live Update content ([Make sure editor have access to the liveupdate url directly during a "Build HTML5" · Issue #5593 · defold/defold · GitHub](https://github.com/defold/defold/issues/5593))
4. To set the output name of Live Update’s .zip file. Also, bob.jar could put it in the bundle output folder.

---

<div class="post-metadata">

**Author:** ![BunBunBun](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bunbunbun/32/25691_2.png) [@BunBunBun](https://forum.defold.com/u/BunBunBun)\
**Post date:** [March 2, 2021, 2:12pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/3 "2021-03-02T14:12:51Z")

</div>

Thanks a lot @aglitchman for sharing this very amazing and useful extenstion / project!

Finally we can use the functional of Live Update more often.

@Mathias_Westerdahl this is what I meant when I said download files locally in my recent thread (“downloading from local directory of HTML5 build”). 🙂

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 2, 2021, 2:28pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/4 "2021-03-02T14:28:24Z")

</div>

Yes, I agree that will be a good improvement!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 2, 2021, 3:39pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/5 "2021-03-02T15:39:23Z")

</div>

This right? [Make sure editor have access to the liveupdate url directly during a "Build HTML5" · Issue #5593 · defold/defold · GitHub](https://github.com/defold/defold/issues/5593)

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [March 4, 2021, 12:31pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/6 "2021-03-04T12:31:13Z")

</div>

> [@britzl](#):
>
> This right? [https://github.com/defold/defold/issues/5593](https://github.com/defold/defold/issues/5593)

Yes!

Also, these

- [Live Update: ability to specify output filename of .zip file · Issue #5604 · defold/defold · GitHub](https://github.com/defold/defold/issues/5604)
- [Live Update: be able to disable creation of temporary files (.arcd/.arci) · Issue #5603 · defold/defold · GitHub](https://github.com/defold/defold/issues/5603)
- [Live Update: load missing resources with resource.store\_archive() · Issue #5602 · defold/defold · GitHub](https://github.com/defold/defold/issues/5602)

😇

---

<div class="post-metadata">

**Author:** ![BunBunBun](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bunbunbun/32/25691_2.png) [@BunBunBun](https://forum.defold.com/u/BunBunBun)\
**Post date:** [March 5, 2021, 11:01am UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/7 "2021-03-05T11:01:59Z")

</div>

Also, I didn’t find it by searching the forum, I don’t know if this feature was discussed earlier, but will be nice to have the opportunity to see the progress of the downloading resources via Live Update.

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [March 13, 2021, 12:38pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/8 "2021-03-13T12:38:52Z")

</div>

New version 1.1.1 is released! Changes:

- Download progress! [Under the hood, it uses `FileLoader` from `dmloader.js` to download files.](https://github.com/indiesoftby/defold-liveupdate-reszip/blob/main/liveupdate_reszip/lib/web/library_reszip.js)
- Now you can use `reszip.lua` to:
  - Load only missing resources from .zip on demand.
  - Load all resources from .zip - pass `nil` as the second argument to the `reszip.request_and_load_zip` function.

Also, I [updated the demo](https://indiesoftby.github.io/defold-liveupdate-reszip/latest/index.html) to show how to handle downloading progress of the .zip file.

[https://forum-defold-uploads.b-cdn.net/original/3X/f/9/f93ecd4c1a1a61934f3f5aeaf5cfda3e59500e44.mp4](https://forum-defold-uploads.b-cdn.net/original/3X/f/9/f93ecd4c1a1a61934f3f5aeaf5cfda3e59500e44.mp4)

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [February 15, 2022, 8:42pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/9 "2022-02-15T20:42:16Z")

</div>

Yet another game where we used the incredible capabilities of Defold’s Live Update is **[Fish Eat Fish 🐠](https://poki.com/en/g/fish-eat-fish)**, an HTML5 game. @notbadgun mainly developed the game, whereas my task was to optimize the framerate and reduce its size.

Thanks to the Live Update + ResZip, the game’s total size is only 4 MB! After the start, the game downloads the HD version of the graphics (10 MB, look at the “pie” progress bar in the corner) and applies it depending on hardware capabilities:

 ![Fish Eat Fish - ResZip HD-SD](https://forum-defold-uploads.b-cdn.net/original/3X/2/7/27fd024b85d879a9c302d822dac1c568554b3fee.jpeg)

I’ll share more information about that later, i.e. I need to prepare an example project on how to do that.

---

<div class="post-metadata">

**Author:** ![BunBunBun](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bunbunbun/32/25691_2.png) [@BunBunBun](https://forum.defold.com/u/BunBunBun)\
**Post date:** [November 15, 2022, 12:09pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/10 "2022-11-15T12:09:35Z")

</div>

up! 🙂

> [@aglitchman](#):
>
> [Live Update: ability to specify output filename of .zip file · Issue #5604 · defold/defold · GitHub](https://github.com/defold/defold/issues/5604)

much needed feature!

---

<div class="post-metadata">

**Author:** ![aglitchman](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aglitchman/32/19432_2.png) [@aglitchman](https://forum.defold.com/u/aglitchman)\
**Post date:** [October 31, 2023, 1:57pm UTC](https://forum.defold.com/t/reszip-a-ready-to-use-lua-module-and-example-project-on-how-to-use-liveupdate/67686/11 "2023-10-31T13:57:24Z")

</div>

Version 1.4.0.

In this version, resource saving is done through a new API `liveupdate.add_mount`. Therefore `miniz` and other code has been removed.

Current users of the extension only need to update the extension version!

And, still, ResZip includes a custom http downloader with progress unlike the official `http.request` function (when already?).
