执行 JavaScript 来渲染 HTML 以进行服务器端缓存

发布于 2024-07-04 21:05:50 字数 443 浏览 5 评论 0原文

网站提供的许多小部件实际上是 JavaScript 代码,通过 DOM 操作或 document.write() 生成 HTML。 我不想通过额外的请求进一步减慢浏览器的速度,也不想相信另一个提供者能够快速、可靠且不会更改小部件输出,我想执行* JavaScript 来生成呈现的 HTML,然后保存该 HTML 源代码。

我研究过的事情似乎不可行或太困难:

  1. 链接浏览器(不是 lynx!
  2. 无头使用 Xvfb 加 Firefox 加 Greasemonkey(yikes
  3. ) Java 浏览器工具包 Cobra(最好的选择!

有什么想法吗?

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

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.­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

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

  1. The Links Browser (not lynx!)
  2. Headless use of Xvfb plus Firefox plus Greasemonkey (yikes)
  3. The all-Java browser toolkit Cobra (the best bet!)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

波浪屿的海角声 2024-07-11 21:05:55

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

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)."

肥爪爪 2024-07-11 21:05:54

如果您只是使用纯 JS,Rhino 应该可以解决问题。 但如果 JS 代码实际上调用 DOM 方法等,您将需要一个成熟的浏览器。 Crowbar 可能会帮助你。

这真的会让用户的操作速度更快而不会引起兼容性问题吗?

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.

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

烟酉 2024-07-11 21:05:53

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文