[Ur] local urls for the script directive

Austin Seipp mad.one at gmail.com
Tue May 1 15:03:42 EDT 2012


At one point when I was fiddling with stuff like this, my first hacky
solution was basically make a module with a single page that used
returnBlob to return a raw text string with a MIME type of
text/javascript - from a library point of view, my .urp file then
included a directive like 'script /Mathjax/js' where 'js' is the
aforementioned page handler, so it would get brought into every page.
This has the obvious downside that it 'takes over' the Mathjax module
namespace and also it hardcodes the path, which isn't great. It also
has the much worse downside that you basically have to escape your
javascript and insert it as a raw string literal into the module (I
tend to abuse things like this; sorry Adam!)

Here's a fully working example of this idea:
https://github.com/thoughtpolice/ur-mathjax

A few months ago I posted a compiler patch to the list that had
support for an 'inlineScript' directive that you could point at a
local Javascript file, and it would 'bake' the source directly into
the compiler and put it into pages on page requests (and FYI I
modified my mathjax lib to use this patch, and it was much nicer, but
I never pushed that branch apparently, and that machine is currently
KIA until I fix the bootloader...) This is much more robust,
especially when you want to bind existing Javascript libs with a small
Ur shim; Adam however was not keen on this patch because it was very
ad-hoc and specific to JavaScript.

I agree with that assessment looking back on it; a more general way to
either bake resources/scripts into the compiled executables, or a
viable deployment abstraction would be a much better way to go in the
long run. But I don't know what the latter would look like, and it's
something that is fairly important as Edward said elsewhere, so
perhaps that ground should be treaded carefully.

I hope it helps.

On Wed, Apr 25, 2012 at 6:30 PM, Timothy Beyer <beyert at fastmail.net> wrote:
> Hi,
>
> I recently figured out how to use the javascript FFI properly, but one thing
> that has bothered me is that my javascript files need to be hosted somewhere,
> or locally on another web service on the same machine.
>
> Is there any way that Ur/Web itself can host the js file? I've read the
> documentation as much as possible, but I'm still not sure how to do something
> like this.
>
> For a script named "jsAlert" in a project called "AlertJs" [1], I've tried the
> following directives:
>
> script http://[web-host-url-and-path-goes-here]/jsAlert.js
> script http://localhost/jsAlert.js
> script http://localhost/AlertJs/jsAlert.js
> script http://localhost:8080/jsAlert.js
> script http://localhost:8080/AlertJs/jsAlert.js
> script jsAlert.js
> script ./jsAlert.js
>
> Other than the externally hosted js file script directive mentioned first,
> (which works properly, but I'd rather not also run lighttpd or nginx if
> possible) none of the other script directives have worked.  The latter two
> attempts I knew would not work, but I tried anyway for the sake of
> completeness.  I think that there is already a way to do this, because the
> setInner example in tests/ does specifies the host as localhost, but I couldn't
> get that particular example to work properly, so I'm not sure.
>
> Should I be using the "allow url ..." directive?
>
> Would the "rewrite" directive allow me to do this?
>
> Also, it would be nice if Ur/Web logged a failure to find the js file on the
> console, when the "script" directive is invalid. (I haven't tried the debug
> flag, maybe that enables such a behavior?) I unknowingly had the javascript FFI
> otherwise working in a recent attempt, only to find out that the only issue was
> that it couldn't find the javascript definitions.
>
> Regards,
> Tim
>
> [1] I access the project at the URL http://localhost:8080/AlertJs/main, as with
> most Ur/Web projects.  I don't use any rewrite directives on this project, yet.
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur



-- 
Regards,
Austin



More information about the Ur mailing list