0

I'd like to insert a couple of large libraries in arbitrary sites, or on localhost, do some stuff, and get a result out.

What is the most efficient way to do this? Inserting a large text node is probably not the most optimal solution.

Also, is it possible to be in offline mode for local server use? For instance, to have UI4J wrap less.js and render stuff.

Or does it have to be online and resources served through localhost?

Naftali
  • 144,921
  • 39
  • 244
  • 303
mjs
  • 21,431
  • 31
  • 118
  • 200

1 Answers1

1

You could load javascript from both local path and from cdn. Its not required to run local web server to load javascript. Just put the resource (css, image, js) to same folder/package of html file.

I also add sample code that execute less.js api from Java. You could load jess.js from both cdn or local disk.

Community
  • 1
  • 1
  • I was actually able to get rhino and envjs to work yesterday. Turns out I spent about 4 hours of debugging why it was suddenly so slow. Turns out I had an accidental field breakpoint in Intellij. However, i decided to try your example today, and benchmarked the two, and was a bit dissapointed that it wasn't faster, but actually 10 times slower. Then I decided to optimize it, and it got to speed up to a whopping 5-6 times faster than rhino! I'd be interesting in submitting a benchmark to the git repo if you are intersted in seeing and sharing the results. – mjs Oct 06 '15 at 10:23
  • @momo It will be greate if you could push your benchmark code to ui4j repo https://github.com/ui4j/ui4j –  Oct 06 '15 at 12:14
  • Ok, I will try to make time for doing that soon. – mjs Oct 06 '15 at 15:18
  • @Öszan, is there a "better" way to place like a hashmap on window, than executing a script to get window and place a java object? How will that work with getters and dot notation? For isntance, window.mymap = new HashMap(); ... I noticed there is are the javafx.beans.property classes, I'd imagine a window like object might already be available to setMembers on, do you know? – mjs Oct 07 '15 at 07:13
  • I've tried new SimpleMapProperty(engine, "myprop") but that wasn't available in the browser. – mjs Oct 07 '15 at 07:35
  • Is there a a way to put a hashmap onto the page, and be able to access it using dot notation ? What is the most efficient way to do this? – mjs Oct 07 '15 at 07:59
  • Sorry, for going on, but there is a way through WebkitDocument which extends EventTarget ( which perhaps also should add those methods to the Document contract so one can do those if needed ) .. however, that would set a property on document so I can execute document.myvariable. However, I am not sure how this is done, and I'd like to set a dot accessible property on the window object. It has to be possible I feel. So I don't have to executeScript('window') ... – mjs Oct 07 '15 at 10:06
  • @momo I just update the sample code which does not require to use custom Java callback. https://github.com/ui4j/ui4j/blob/master/ui4j-sample/src/main/java/com/ui4j/sample/LessJs.java#L41 –  Oct 07 '15 at 17:24
  • I think you have mistaken my quesiton for something else, plus, your example can be shortened to page.executeScript("var css; less.render(... css = output.css; ); css"); I was looking for a way to get hold of the window object. It should already have been loaded at some point prior, since document is available on the Java side, and that lives on the window object JS side. I am able to get hold of the WebKitDocument and call EventTarget::setProperty(key, obj) .. but that places it on the document. I'd rather do the same but place it on the window. – mjs Oct 08 '15 at 02:55