How can I dynamically reference images from my assets via javascript?


Hi!

I’d like to dynamically reference images from my assets (uploaded images) via javascript. How can I do that?

The only solution I’ve come up until now is to put all images into the page and hide them first via display:none css code. But this will cause the page to load all images in advance.

I’d really like to keep the assets on unbounce and not split it up to external resources from another server if not necessary.

Any ideas?
Thanks!


2 replies

Userlevel 3
Badge +1

Hi Paul - while you’re not able to reference images directly from your image library, what you could do is load all of the images to a separate Unbounce page. As long as that page remains published and in your account, those image links will remain static, so you could reference the links from that page and only load the necessary ones on your actual landing page as needed.

ugly 😉

how about a global javascript funktion like “getUnbounceResourceUrl(‘image-name’)” which takes care of that?

Reply