jsdom窗口缓存
在express.js 中使用 jsdom.jsdom() 我创建了一个带有一些“基本”布局标记的文档,并将一些客户端库(例如 jQuery)附加到其窗口。
如果只需执行一次此设置,那就太好了。
问题是窗口文档的 DOM 将根据请求的 url 发生变化。有没有办法让每个请求从同一个缓存的窗口对象开始并增强它,或者是否必须在每个请求上从头开始设置?
Using jsdom.jsdom() in express.js I create a document with some 'base' layout markup and attach a few client side libraries such as jQuery to its window.
It would be nice to only have to do this setup once.
The problem is that the DOM of the window's document will change depending on the requested url. Is there a way for each request to start from the same cached window object and enhance it or does it have to be setup from scratch on every request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来你想要一个简单的 JavaScript 对象哈希?
It sounds like you want a simple JavaScript object hash?
我认为这是不可能的。当您使用 jsdom 构建器创建新文档时,您指定的任何自定义选项只会影响当前正在创建的文档。此后创建的任何其他文档都将依赖于默认功能。
然而,您实际上可以修改这些默认功能——我认为这就是您所追求的。在创建任何文档之前,您可以为所有将来的文档修改这些默认值:
通过阅读 jsdom 的 README 可以获得每个选项的说明。
I don't think this is possible. When you create a new document using the jsdom builder, any custom options you specify will only affect the document that is currently being created. Any additional documents created after this point will rely on default features.
However, you can actually modify these default features -- which is what you're after, I think. Before you create any documents, you can modify these defaults for all future documents:
An explanation of each option is available by reading jsdom's README.