Download ajax application using jsdom

I am looking for a solution to download a client-side application (written in Backbone.js) on the server so that I can serve the right content for crawlers and non-js users.

I played with jsdom and nodejs in an attempt to download the application and can get it before loading it in the base content of the template, but the application never seems to start.

I tried 2 different solutions to make sure that I have all the necessary dependencies and the application loads correctly:

  • I tried using jsdom.env () with all the scripts that are usually included in the string.
  • I tried using jsdom.jsdom () and making sure that FetchExternalResources, ProcessExternalResources, and MutationEvents were correct and included.

However, the window.onload event does not seem to fire. I am wondering if jsdom might not run this or maybe call it a callback after it usually started?

Is this a task that is possible in jsdom?

+4
source share
1 answer

I would not wait for window.onload, as jsdom does not extract images / css (for now). When using jsdom.env, you can simply handle the callback as the β€œhey, you're done now” event.

If your application depends on window.onload, you can call it in the above callback.

+5
source

All Articles