#How do I bundle static js files? in /public or in /assets?

1 messages · Page 1 of 1 (latest)

vague ermine
#

I'm confused what the correct practice is. I see that dioxus comes with an assets folder, should i be putting my scripts in there? or should i make a public folder and put them in there? and how to i reference these assets?

i looked at the docs but i found it confusing it seems there are two static directory variables: public_dir and asset_dir?
https://dioxuslabs.com/learn/0.6/CLI/configure/#config-example

A fullstack crossplatform app framework for Rust. Supports Web, Desktop, SSR, Liveview, and Mobile.

#

My usecase is i have a tree of js files, like a.js which needs to lazily load b.js from relative path. So how should i structure these files in my project and how do i ensure they can see eachother?

chrome dome
#

For assets you should use asset!()

#

The new public dir is meant for arbitrary files like robots.txt that need to exist outside the assets folder

#

you can include folders with asset!() and then join file names against the folder

format!("{}/main.js", asset!("/assets/folder-of-js"))
vague ermine
#

okay great, and a quick quesiton:

if i have an assets say /main.js, and that js script itself needs to call relative files like iframe.html, how do i make sure those files are fetchable by the script?

vague ermine
#

nvm solved it. The answer is to emit the hashed filenames via the variables we bind teh asset macros to. Thanks!

vague ermine
#

@chrome dome Actual yeah this is a bit unwieldy, could you provide some guidance:

So i have a main.js that inside imports "./b.js". THe problem is it appears that doxus mangles the asset name into "b-hashed.js" so i can't clearly call it from the main.js file. In the devtools network tab the response is the dioxus router html page which yeah is wrong

Do u have any advice for this?

vague ermine
#

Ahh it looks like what i need is hashless assets. It looks like dioxus 0.7 solves this. I'll look more into it but any guidance would be appreciated

#

oh i can't use 0.7 yet, yeah is there a solution for this on 0.6 haha

bleak shard
#

In 0.6, the assets in the asset folder (set in your cargo.toml) are copied over without a hash

vague ermine