jimetevenard / saxonjs-worker

SaxonJS at work in the context of a Web Worker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Saxon JS in a Worker

Live demo at https://jimetevenard.github.io/saxonjs-worker/

SaxonJS at work in the context of a Web Worker.

Web Workers operate in a separated thread from the main web page, allowing you to run transformations on documents of consequent size without freezing the UI.

The main point of this demo is that the Web Worker context has no access to the DOM API, needed by SaxonJS.

As a workaround, I do use the NodeJS version of SaxonJS, embedded with the help of npm and Browserify.

For Node.js (...) The Saxon product includes its own XML parser and DOM implementation, rather than relying on the parser and DOM library supplied by the browser vendor.
See SaxonJS documentation

Running locally

With nodeJS installed, just run the following :

npm install
npm start

And go to http://localhost:8080/

Details

The package.json build script :

  • Compiles the XSLT into a SEF file
  • Browserifies the saxon-worker.js script (resolving the require('saxon-js') and the local code into a single file)
  • We can then, in our main.js script
    • Get the SEF via http
    • Instantiate a worker running the compiled worker.js file

When the transform button is clicked, the SEF, XML source and a few params are sent to the worker.

The main script can subscribe to the messages sent by the worker to display the result.

VoilĂ  !

About

SaxonJS at work in the context of a Web Worker


Languages

Language:HTML 55.4%Language:CSS 20.4%Language:JavaScript 19.0%Language:XSLT 5.3%