Take the 2-minute tour ×

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
I know i can edit js files by hand and split them and load them separately. Perhaps my question was not clear. I'm asking how to prevent fay generating all this code, once i saved it into separate file? I tried all the flags including mentioned by you. And the result file still have a lot of stuff included. I want it generate just the code of the module itself, do not include any of the stdlib and jquery. –  Vagif Verdi Sep 9 '13 at 22:25

Your Answer


