执行JavaScript以呈现用于服务器端缓存的HTML

时间:2022-03-26 15:04:02

There are lots of widgets provided by sites that are effectively bits of JavaScript that generate HTML through DOM manipulation or document.write(). Rather than slow the browser down even more with additional requests and trust yet another provider to be fast, reliable and not change the widget output, I want to execute* the JavaScript to generate the rendered HTML, and then save that HTML source.­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

网站提供了许多小部件,这些小部件实际上是通过DOM操作或document.write()生成HTML的JavaScript。而不是通过额外的请求减慢浏览器的速度,并且信任另一个提供者快速,可靠并且不更改窗口小部件输出,我想执行* JavaScript来生成呈现的HTML,然后保存该HTML源。

Things I've looked into that seem unworkable or way too difficult:

我所看到的事情似乎不可行或太难:

  1. The Links Browser (not lynx!)
  2. 链接浏览器(不是lynx!)

  3. Headless use of Xvfb plus Firefox plus Greasemonkey (yikes)
  4. 无头使用Xvfb加Firefox和Greasemonkey(yikes)

  5. The all-Java browser toolkit Cobra (the best bet!)
  6. 全Java浏览器工具包Cobra(最好的选择!)

Any ideas?

** Obviously you can't really execute the JavaScript completely, as it doesn't necessarily have an exit path, but you get the idea.

**显然你不能完全执行JavaScript,因为它不一定有退出路径,但你明白了。

3 个解决方案

#1


2  

Wikipedia's "Server-side JavaScript" article lists numerous implementations, many of which are based on Mozilla's Rhino JavaScript-to-Java converter, or its cousin SpiderMonkey (the same engine as found in Firefox and other Gecko-based browsers). In particular, something simple like mod_js for Apache may suit your needs.

*的“服务器端JavaScript”文章列出了许多实现,其中许多实现基于Mozilla的Rhino JavaScript-to-Java转换器,或其表兄SpiderMonkey(与Firefox和其他基于Gecko的浏览器中的引擎相同)。特别是,像Apache的mod_js这样简单的东西可能适合您的需求。

#2


2  

If you're just using plain JS, Rhino should do the trick. But if the JS code is actually calling DOM methods and so on, you're going to need a full-blown browser. Crowbar might help you.

如果你只是使用普通的JS,Rhino应该可以做到。但是如果JS代码实际上调用DOM方法等等,那么你将需要一个成熟的浏览器。撬棍可能会帮助你。

Is this really going to make things faster for users without causing compatibility issues?

这是否真的会在不引起兼容性问题的情况下为用户提供更快的速度?

#3


2  

There's John Resig's project Bringing the Browser to the Server: "browser/DOM environment, written in JavaScript, that runs on top of Rhino; capable of running jQuery, Prototype, and MochiKit (at the very least)."

John Resig的项目将浏览器引入服务器:“用JavaScript编写的浏览器/ DOM环境,运行在Rhino之上;能够运行jQuery,Prototype和MochiKit(至少)。”

#1


2  

Wikipedia's "Server-side JavaScript" article lists numerous implementations, many of which are based on Mozilla's Rhino JavaScript-to-Java converter, or its cousin SpiderMonkey (the same engine as found in Firefox and other Gecko-based browsers). In particular, something simple like mod_js for Apache may suit your needs.

*的“服务器端JavaScript”文章列出了许多实现,其中许多实现基于Mozilla的Rhino JavaScript-to-Java转换器,或其表兄SpiderMonkey(与Firefox和其他基于Gecko的浏览器中的引擎相同)。特别是,像Apache的mod_js这样简单的东西可能适合您的需求。

#2


2  

If you're just using plain JS, Rhino should do the trick. But if the JS code is actually calling DOM methods and so on, you're going to need a full-blown browser. Crowbar might help you.

如果你只是使用普通的JS,Rhino应该可以做到。但是如果JS代码实际上调用DOM方法等等,那么你将需要一个成熟的浏览器。撬棍可能会帮助你。

Is this really going to make things faster for users without causing compatibility issues?

这是否真的会在不引起兼容性问题的情况下为用户提供更快的速度?

#3


2  

There's John Resig's project Bringing the Browser to the Server: "browser/DOM environment, written in JavaScript, that runs on top of Rhino; capable of running jQuery, Prototype, and MochiKit (at the very least)."

John Resig的项目将浏览器引入服务器:“用JavaScript编写的浏览器/ DOM环境,运行在Rhino之上;能够运行jQuery,Prototype和MochiKit(至少)。”