装入有jsdom AJAX应用程序 [英] Loading ajax app with jsdom

查看:214
本文介绍了装入有jsdom AJAX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个解决方案来引导客户端应用程序在服务器上(写在Backbone.js的),这样​​我就可以起到正确的内​​容,爬虫和非JS的消费者。

I'm looking for a solution to bootstrap a client side app (written in Backbone.js) on the server, so that I can serve correct content to crawlers and non-js consumers.

我一直在玩弄jsdom和放大器;在试图nodejs来引导该应用,并且可以得到它,只要装载在基本的模板内容,但该应用似乎不会开始。

I've been playing around with jsdom & nodejs in an attempt to bootstrap the app, and can get it as far as loading in the basic template content, but the app appears to never start.

我已经试过2个不同的解决方案,以确保我有必要所有的依赖和应用程序是正确加载:

I've tried 2 different solutions to make sure that I have all the dependencies necessary and the app is loading correctly:

  1. 在我尝试使用jsdom.env()与所有的脚本,通常包括内联。
  2. 在我尝试使用jsdom.jsdom(),并​​确保FetchExternalResources,ProcessExternalResources和MutationEvents都是正确的和。

无论是看起来虽然火灾window.onload事件。我想知道如果jsdom可能不会触发这个,或者调用它的回调它会通常被解雇后?

Neither seem to fire the window.onload event though. I'm wondering if jsdom possibly doesn't fire this, or maybe calls it's callback after it would have normally been fired?

这是一个任务,那就是有可能在jsdom?

Is this a task that is possible in jsdom?

推荐答案

我是不会等待的window.onload为jsdom不获取图像/ CSS(还)。当使用jsdom.env,你可以简单地把回调作为哎,现在一切准备就绪事件。

I wouldn't wait for window.onload as jsdom doesn't fetch images/css (yet). When using jsdom.env, you can simply treat the callback as a "hey everything is ready now" event.

如果您的应用程序依赖于window.onload的,你可以在里面前面提到的回调触发它。

If your app relies on window.onload, you can trigger it inside the aforementioned callback.

这篇关于装入有jsdom AJAX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆