Question

I tried fay-jquery and the included sample test.hs file results in whooping 150 kb of js file. Even with closure compiling it is still 20 kb.

I understand that it must carry a runtime, stdlib and jquery wrappers with it.

I can tell fay not to generate stdlib (--no-stdlib and --no-builtins flags). But i do not know how to tell it not to include jquery code.

So my question is, how can i split those static parts into a separate js file and only generate module specific code?

This way large parts of code will be loaded only once (and cached) and i can create many smaller js files for separate web pages.

Was it helpful?

Solution

Yes it's safe to split modules up, as of Fay 0.16 all modules can exist standalone (before that you could still have the runtime and fay-base separate). There are some flags for this, --print-runtime and --no-stdlib. Compile with optimizations (-O, this increases the output size, but closure will be able to minimize it even better).

Also remember that the web server should gzip this. That brings the code size down to 4.5kiB. That's pretty decent, right?

You might want to consider putting all of your javascript in one file, that means a slower initial load but then users will have it cached for future page loads.

The reason the file size is so big is that fay-jquery has a lot of FFI bindings which produce a lot of transcoding information. I think fay-jquery could be optimized a lot here to for instance use Ptr JQuery rather than just JQuery in the types, or by figuring out that a lot of this is unnecessary while compiling, or abstracting the conversions more in the compiler's output.

Another possible issue I realized a couple of days ago is that the output is now in the global scope rather than in a closure, which might mean that google closure can't remove redundant code as well as previously (haven't had time to investigate this yet). The modules generation should perhaps be changed to produce a closure for each module.

Also see Reducing output size on the wiki.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top