Generate Smallest Possible Dependency Chain for a File

Hi everyone,

I want to compile a main.go file down to javascript code and import it into the frontend. This works fine, but the resulting js file is massive. The main file I’m using depends on 10 files, which together collectively amount to around 10k lines of code. However, most of this code is not needed by the functions in my main.go file.

Does anyone know of any way to compile my file such that it only takes the bare minimum code needed from these other 10 files to compile correctly (so that the resulting generated js file becomes significantly smaller?)

Thank you everyone for your help

How do you do this? (just curious)

According to the gopherjs README -m removes dead code.

Hi, I’m using gopherjs

Have you tried -m?

Unfortunately the -m flag minifies the resulting javascript - it does not eliminate dead / unused code.

I was able to find an outstanding open issue in gopherjs here: that addresses my question, but there there doesn’t seem to be a resolution yet. I’ll keep looking but it seems like I might need to roll my own modified compiler or something.

Perhaps try joy. It advertises DCE as a feature.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.