JuliaGizmos / Escher.jl

Composable Web UIs in Julia
https://juliagizmos.github.io/Escher.jl
Other
335 stars 63 forks source link

Better asset loading #82

Open shashi opened 8 years ago

shashi commented 8 years ago

Right now, all assets are loaded from Escher's assets folder, uncompressed and un-concatenated. This is of course not ideal.

Here is a rough sketch of what this could look like in the future:

push!(window.assets, ["a.html", "b.css, "c.js"])

a, b, and c would get concatenated and gzipped (the first time they are needed), and cached in a file under assets/cache with some canonical name like

string(join(sort(["a.html", "b.css", "c.js"]), "+")  |> hash) * ".html.gz"

Problem 1: Some polymer files are repeatedly included in others. So if window.assets is pushed to a second time, it should be possible to exclude what was already sent. And the corresponding statements must be stripped. This is not only nice to have, not having this is a fatal error since elements will try to register themselves more than once.

Problem 2: cache invalidation. If one is editing the assets file, when should they be cleared? a manual way to do it can be provided: escher --clear-cache.

mdcfrancis commented 8 years ago

It feels like we want a solution close to watchify where the asset file is generated as a bundle which is then available to the browser when changed. I could see each .jl file having an associated bundle. Julia could manage a package.json file and have watchify build it for those who want the live behavior? I don't believe polymer supports a way to unregister (or update) components, so perhaps it is not so bad to force the reload of the page on asset change?

https://groups.google.com/forum/#!searchin/polymer-dev/unregister/polymer-dev/GmLvoMjfk54/iO3pFyD9JTwJ

shashi commented 8 years ago

It seems to me that hot-loading Javascript is made difficult by the fact that web components cannot be re-registered. I don't think that's that big a deal right now as much as packing asset files together in a compact package for faster load time.

There are other options that I missed out here:

  1. HTTP2 push: https://www.igvita.com/2013/06/12/innovating-with-http-2.0-server-push/
  2. Caching with WebWorkers - this is made easy by polymer https://github.com/PolymerElements/platinum-sw

I think we should implement both of these