# Best way to dynamically load assets

**URL:** <https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905>\
**Category:** Questions\
**Created:** [July 27, 2020, 12:39pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905 "2020-07-27T12:39:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [July 27, 2020, 12:39pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/1 "2020-07-27T12:39:35Z")

</div>

Does defold support dynamically loading assets? I intend to use quite a few really hi-res graphics (4k graphics) for my next game (I have to use hi-res since svg isn’t supported), and I would like a better loading system than just a ten-second lag on program launch.  
Thanks!

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 27, 2020, 1:28pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/2 "2020-07-27T13:28:44Z")

</div>

Yes! Live update is what you’re looking for:

> **[Live update content in Defold](https://defold.com/manuals/live-update/)**
>
> The Live update functionality provides a mechanism allowing the runtime to fetch and store resources to the application bundle that were intentionally left out of the bundle at build time. This manual explains how it works.

I used it in an HTML5 game, it worked great. For apps you have to store the content on a server, all explained in the docs above.

---

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [July 27, 2020, 1:34pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/3 "2020-07-27T13:34:27Z")

</div>

Can I self-host instead of using AWS?

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 27, 2020, 1:35pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/4 "2020-07-27T13:35:45Z")

</div>

Which platform(s) are you targetting?

---

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [July 27, 2020, 1:36pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/5 "2020-07-27T13:36:48Z")

</div>

Desktop and mobile (not web, but dealing with large number of massive assets)

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 27, 2020, 1:38pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/6 "2020-07-27T13:38:59Z")

</div>

For desktop you might be able to store them locally, but not sure if that makes sense. For mobile I believe the only option is AWS.

---

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [July 27, 2020, 1:40pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/7 "2020-07-27T13:40:14Z")

</div>

zip isn’t supported on mobile?

---

<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:** [July 27, 2020, 1:41pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/8 "2020-07-27T13:41:08Z")

</div>

You can self host your files on any file server (not just AWS).

Not sure what other users use though. @pkeod @agulev, do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [July 27, 2020, 1:41pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/9 "2020-07-27T13:41:48Z")

</div>

how do I do that? is there a hidden “other” option in live update?

---

<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:** [July 27, 2020, 1:53pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/10 "2020-07-27T13:53:46Z")

</div>

You export to “.zip” as you mentioned.  
Then (regardless of AWS or not), you will need to load these files from a file server. The .zip contains the files that the live update will request later on.

---

<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:** [July 27, 2020, 1:54pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/11 "2020-07-27T13:54:41Z")

</div>

You can try it with a local python server, e.g. “python m SimpleHTTPServer”, which will give you a file server (from the current directory), at “[http://localhost:8000](http://localhost:8000)”

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [July 27, 2020, 4:42pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/12 "2020-07-27T16:42:24Z")

</div>

I think there was a misunderstanding in the original post. @Griffin is not needing live update features but instead needing to use collection proxies to not load everything at once. [Collection proxy manual](https://defold.com/manuals/collection-proxy/)

Use Monarch and only reference the atlases you need on the screens they are mentioned on. This makes it easy for general assets, you load between screens.

We have 50+ location backgrounds often in our games, these are loaded and unloaded dynamically with collection proxies too. So max there are 2 loaded at once and they are usually swapped between screens.

What do you mean by 4k graphics? You should know that max texture size matters a lot especially on mobile you should try to keep atlases at least below 2048, but even targeting 1024 is also a good idea. This can be done with texture profiles.

---

<div class="post-metadata">

**Author:** ![Griffin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/griffin/32/36764_2.png) [@Griffin](https://forum.defold.com/u/Griffin)\
**Post date:** [September 20, 2020, 8:09am UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/13 "2020-09-20T08:09:50Z")

</div>

Is there also a way to download and load assets from a url? Or will I have to make an atlas with a 1x1 image of every single hexadecimal color and make my own encoder with an absolutely ridiculous quantity of gui nodes?

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [September 20, 2020, 10:23pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/14 "2020-09-20T22:23:04Z")

</div>

You can download images from the net and set their textures to nodes. For other assets, you can download them too, and as long as you have a way to make them useful, you can use them.

Here’s a bare bones example of downloading an image and setting it on a node.

```lua
http.request(url, "GET", function(self, id, response)
	if response.status ~= 200 and response.status ~= 304 then
		print("Couldn't access URL of image")
	else
		local downloaded_image = image.load(response.response)
		if not downloaded_image then return nil, "Failed to load image" end
		
		gui.new_texture(url, downloaded_image.width, downloaded_image.height, downloaded_image.type, downloaded_image.buffer)
		gui.set_texture_data(url, downloaded_image.width, downloaded_image.height, downloaded_image.type, downloaded_image.buffer)
		gui.set_texture(my_node, url)
	end
end, nil, nil, {timeout = 0.75})

```

Typically if you want to download resources like this you will also want to cache them to disk and use their cached versions based on a file manifest so you do not waste your user’s bandwidth. I’ll post an example of how to do this sometime in the future.

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [April 25, 2023, 8:05pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/15 "2023-04-25T20:05:51Z")

</div>

> [@Pkeod](#):
>
> Typically if you want to download resources like this you will also want to cache them to disk and use their cached versions based on a file manifest so you do not waste your user’s bandwidth. I’ll post an example of how to do this sometime in the future.

Sorry to necro this thread but would you still be up for doing this, @Pkeod ? 😅

Or maybe someone knows an example of this that already exists!

I’m personally looking for a solution that would work on HTML5.

---

<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:** [April 25, 2023, 9:18pm UTC](https://forum.defold.com/t/best-way-to-dynamically-load-assets/65905/16 "2023-04-25T21:18:46Z")

</div>

> [@Alex\_8BitSkull](#):
>
> I’m personally looking for a solution that would work on HTML5.

Maybe this is what you are looking for - [ResZip: a ready-to-use Lua module and example project on how to use LiveUpdate](https://forum.defold.com/t/use-live-update-to-improve-load-speed-of-html5-game/67686)
