Js code compression / minimising

Is there a tool to take out some/all/most of the unused js in a typical file?

My app with no additional assets than haxeui is nearly 1MB and I was just wondering what tips/tricks were known to cut it down a bit or a lot. Thanks!


openfl build html5 -minify

Yes. Look at this Openfl html5 -minify throwing error .

1 Like

You could also do openfl build html5 -final, which does a -minify and DCE and js-flatten, I think

1 Like

After compile I get 2 seprate folders having same content, “assets/img/” folder and “img/” folder

Why these duplicate files are made even they are mention in the .js file, which means get loaded on start ( same resources twice from 2 different paths ).

That’s a totally different issue, but here’s how to fix it. Your project.xml file contains the following:

<assets path="assets" rename="assets" />
<assets path="assets/img" rename="img" />

The first of these tags copies the entire “assets/” folder, including “assets/img/”. The second copies the “assets/img/” folder again. To solve the issue, remove one of them.

If you remove the first, you’ll want to add another tag for your sounds, one for your fonts, one for your text assets, etc. (Basically, one per subfolder.)

Or you can remove the second, and then you just need to make sure all your Assets.getBitmapData() calls refer to “assets/img/Whatever.png” rather than “img/Whatever.png.”

Apology for irrelevant issue, I removed the assets/img path, thanks.

You could also use <assets path="assets" exclude="img" /> if you want :wink:

Your method did work for one of my project but now I am stuck again, I have 3 folders in assets img, sound, kharchu now when I try to exclude all three of them using.

<assets path="assets" exclude="kharchu" />
<assets path="assets" exclude="sound" />
<assets path="assets" exclude="img" />

nothing happens and all folders exist in assets directory of html5 build. While having only first line exclude that folder successfully. I am confused here, in html5 build with -final argument copies all the sub folder of assets to root and also keeps the assets folder with sub folder which is default behavior and its very cumbersome :s

Right, that’s going to do the following three things:

  1. Include all assets except those in kharchu/.
  2. Include all assets except those in sound/.
  3. Include all assets except those in img/.

It would be similar to running code like this:

if(myString != "kharchu" || myString != "sound" || myString != "img") {

It’s been a while since I worked with the xml format, but I believe the correct solution is this:

<assets path="assets" exclude="kharchu|sound|img" />
1 Like