phoenixframework / phoenix_html

Building blocks for working with HTML in Phoenix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Proposal] - Build min js

leandrocp opened this issue · comments

phoenix_html.js is pretty small but a min version would be helpful, at least for https://github.com/BeaconCMS/beacon :)

Something along the lines of https://github.com/phoenixframework/phoenix_live_view/blob/ba706fb970a20648408133ba365d8886fc9949f5/config/config.exs#L17-L22

Would a PR be accepted?

Yes, please PR!

I'm not convinced this will save anything real, but worth comparing what a minified output would be size wise :)

worth comparing what a minified output would be size wise

There you go #402 :)

It's not that much in absolute values but it's still something.

Thanks! What are the absolute values?

$ ll assets/js/phoenix_html.js         
.rw-r--r--@ 2.6k leandro  1 Feb 12:16  assets/js/phoenix_html.js

$ ll priv/static              
.rw-r--r--@ 4.4k leandro  1 Feb 12:38  phoenix_html.esm.js.map
.rw-r--r--@ 2.5k leandro  1 Feb 12:38  phoenix_html.esm.js
.rw-r--r--@ 2.6k leandro  1 Feb 12:38  phoenix_html.js
.rw-r--r--@ 1.4k leandro  1 Feb 12:38  phoenix_html.min.js
.rw-r--r--@ 2.5k leandro  1 Feb 12:38  phoenix_html.cjs.js
.rw-r--r--@ 4.4k leandro  1 Feb 12:38  phoenix_html.cjs.js.map

Oh, I have a question: doesn't esbuild imports phoenix_html anyway and then minifies it? I think phoenix_live_view has a minified version for those who want to use it directly but there is little to no reason to use phoenix_html.js directly, no?

LiveDashboard is an example https://github.com/phoenixframework/phoenix_live_dashboard/blob/8d1af95ef5908825b33e4d3508cf8e0ac39f77f1/lib/phoenix/live_dashboard/layout_view.ex

/edit not using a minified version but loading and merging both phoenix_live_view.js and phoenix_html.js

Honestly the savings aren't worth introducing a build step in this case for me, but I will leave it up to @josevalim . Esbuild is solid but another build step will necessarily cost us in terms of maintenance over the life of the project, to minify 80 LOC as an edge case.

Note that users (like beacon) can vendor phoenix_html js and minify themselves in their own build step if absolutely required. I appreciate the legwork on this either way!

little to no reason to use phoenix_html.js directly, no?

@josevalim On BeaconCMS we take a similar approach to LiveDashboard, loading the JS files from the host application, but minified because it runs in PROD.

@chrismccord I was assuming that would be straightforward to build a min version but I get your point and I'm good with vendoring phoenix_html :)

Closing this for now then. Sorry for the false positive @leandrocp !

No worries @josevalim.

Thanks for your time @josevalim and @chrismccord !