[Ur] PATCH: add inlineScript directive

austin seipp as at hacks.yi.org
Sat Sep 3 14:17:45 EDT 2011


The below patch on bitbucket adds support to the compiler for an
'inlineScript' directive, which reads .js files off disk at compile
time and includes them in the urweb app.js file of the resulting
executable.

https://bitbucket.org/thoughtpolice/urweb/changeset/0a1e488e0a67

My main motivation for wanting this is that I would like to write FFI
bindings to JavaScript libraries, that don't require users to use
another web server to serve the static FFI bits. It makes the apps a
little more standalone. It would also let you just include small JS
libraries verbatim as part of your binding - right now I'm writing a
MathJax binding, which has a CDN, so I can use 'script' for the CDN
URL, but I'm using 'inlineScript' for including the small FFI bits.

Using a returnBlob + blessed mime-type trick is possible for trivial
things in this case but it does not easily allow you to include larger
snippets of code since it requires escaping and putting it in an .ur
file. Doing something like this is much easier and does simplify my
tiny library, and hopefully other ones I've written.

I guess another benefit is that it reduces the amount of active
connections the browser has to open to the server for the page. On
mobile devices these extra connections can add up - and while a CDN
may be geographically close, alleviating that somewhat in terms of
speed, Ur/Web applications themselves may not be geographically close,
so taking down the # of requests is always nice, especially for larger
libraries.

There is one thing that freaks me out, and it's the possibility of
name clashes with things defined in app.js. I have another JS binding
that uses the javascript PageDown library and uses inlineScript to
include it inline for the Ur/Web library - roughly 4000 lines of JS.
There weren't any problems, but it still worries me.

If that is a huge problem, I'm willing to refactor the patch so that
it includes all 'inlineScripts' in a distinctly seperate <script> tag
after app.js and all other 'script' directives.

I'd also like this directive to be able to detect relative file paths
(right now, it requires an absolute path) but I think it's fine the
way it is. I've had this patch sitting on my other machine for a few
weeks now almost, so I'd rather just submit it.

Also: this patch adds documentation to the manual for inlineScript, as
well as -dumpTypes and -version since they've been left out. :)

-- 
Regards,
Austin



More information about the Ur mailing list