在服务器上实现HTML DOM重写逻辑 [英] Implementing HTML DOM rewriting logic on the server

查看:96
本文介绍了在服务器上实现HTML DOM重写逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在加载时在客户端大量重写DOM。它通过页面扫描进行特殊标记(认为Markdown)或其他模式,将其替换为有时相当复杂的DOM结构(使用DOM调用,例如 createElement )来设置样式文本,创建图表和图形。

My application does massive rewriting of the DOM on the client side at load time. It traverses the page scanning for special markup (think Markdown) or other patterns, replacing them with sometimes rather complicated DOM structures (using DOM calls such as createElement) to style text but also create diagrams and graphics.

我采用了这种架构,以避免任何构建或预处理步骤。它在桌面浏览器中工作正常,但在移动设备上显着缓慢(几秒钟,甚至在无情优化后)。所以我想重新构建系统以预扫描页面并预先构建DOM。我有一点精神障碍,弄清楚如何做到这一点。显然,我不想在其他服务器端语言中重写所有的Javascript。此外,我想保留在加载时进行建筑的选项,就像现在一样,基本的重写逻辑共享相同的代码。

I adopted this architecture in order to avoid any build or preprocessing steps. It works fine in a desktop browser, but is noticeably slow on mobile devices (several seconds, even after relentless optimization). So I would like to rearchitect the system to pre-scan the page and pre-build the DOM. I'm having a bit of a mental block figuring out how to do this. Obviously, I would prefer not to rewrite all the Javascript in some other server-side language. Also, I would like to preserve the option to do the building at load time as I do now, with the basic rewriting logic sharing the same code.

声音选项是将其构建为节点应用程序,尽管我是一个节点初学者。使用jsdom来解析输入并修改DOM。或者,由于我是XSLT的粉丝,并且被Saxon-CE所吸引,即使这意味着重写所有内容,我也考虑在XSLT中实现扫描/重写逻辑,从节点(用于预构建案例 - 人们是否从节点使用撒克逊?)或浏览器(对于加载时间构建案例)。

The most likely-sounding option is to build this as a node app, although I am a node beginner. using jsdom both to parse the input and modify the DOM. Or, since I am an a fan of XSLT, and intrigued by Saxon-CE, even though it would mean rewriting everything, I also considered implementing the scanning/rewriting logic in XSLT, to be invoked either from node (for the pre-building case--do people use Saxon from node?) or the browser (for the load-time building case).

任何人都可以评论这种方法或抛出替代想法?

Can anyone comment on this approach or throw out alternative ideas?

推荐答案

p>不知道你正在处理大量DOM重写的具体用例,也不知道你的吞吐量要求是多少。也就是说,节点/ jsdom路由的一种替代方法可能是运行一个无头Webkit浏览器的场,并在当前渲染上下文中运行当前的JavaScript。这将允许您将处理从这些pokey移动CPU卸载到任意可扩展的云资源(假设这可能为您的项目/业务负担得起),并且根本不需要重写或调整您当前的工作代码。

Not sure what specific use cases you are tackling with the massive DOM rewriting, nor am I sure what your throughput requirements are. That said, one alternate approach to the node/jsdom route could be to run a farm of headless Webkit browsers, and run your current JavaScript as-is in that live rendering context. That would allow you to offload processing from those pokey mobile CPU's into arbitrarily scalable cloud resources (assuming this might be affordable for your project/business), and skirt the need to rewrite or tweak your current, working code at all.

这篇关于在服务器上实现HTML DOM重写逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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