简体   繁体   English

将HTML页面预渲染到图像中

[英]Pre-rendering html page into image

I want to pre-cache next web page into a thumbnail. 我想将下一个网页预缓存到缩略图中。 Is it possible to pre-render a html page (with css) into an image on-the-fly with javascript/jQuery? 是否可以使用javascript / jQuery将HTML页面(带有CSS)预先呈现为图像? And how to persist that temporary image on the client? 以及如何在客户端上保留该临时映像?

You could do an ajax request requesting an image or a linkt o an image from a script. 您可以执行ajax请求以请求图像或从脚本链接图像。 This srcipt needs to request the data needed from the website and render it using a rendering mechanism. 该脚本需要从网站请求所需的数据,并使用呈现机制进行呈现。 The returned information could be a link to the generated image on the server. 返回的信息可以是到服务器上生成的图像的链接。 Performance could be pretty low depending on the data to be retrieved and rendered. 根据要检索和呈现的数据,性能可能会很低。

This question will show you a solution to render a website and produce a pdf. 该问题将向展示渲染网站并生成pdf的解决方案。 You could use this approach and convert the pdf into an image usinf ImageMagick (needs to be installed on your server). 您可以使用这种方法并将pdf转换为usinf ImageMagick图像(需要在服务器上安装)。

Afaik, that's not possible on the client-side, because it raises security concerns. Afaik,这在客户端是不可能的,因为它引起了安全隐患。 Even the <canvas> element cannot render HTML-elements (only browser plugins are allowed to use the methods provided for that purpose). 甚至<canvas>元素也无法呈现HTML元素(仅允许浏览器插件使用为此目的提供的方法)。

What is the site written in?? 网站写的是什么? If you have server side capabilities you could probably do it and send the image to be cached. 如果您具有服务器端功能,则可能可以做到这一点并发送要缓存的图像。 Is not possible from jquery or javascript as far as I know. 据我所知,不可能从jquery或javascript中获取。

Unless your page is absurdly complex, then it's more likely your bottleneck is in the network, rather than rendering. 除非您的页面非常复杂,否则您的瓶颈更有可能在网络中,而不是在呈现中。 You can easily preload the html page and all its important resources (eg images, multimedia, etc), so that when the user go to the next page, you don't need to hit the network anymore and will load it from local cache. 您可以轻松地预加载html页面及其所有重要资源(例如图像,多媒体等),以便当用户转到下一页时,您不再需要访问网络并将其从本地缓存中加载。

There are a few techniques you can use to preload HTML files, invisible iframe is probably the easiest (though I never tried it myself). 您可以使用几种技术来预加载HTML文件,不可见的iframe可能是最简单的(尽管我自己从未尝试过)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 D3预渲染 - D3 Pre-Rendering 在JavaScript中的画布上预渲染动画 - Pre-Rendering an animation on a canvas in javascript GridLayout使用灰色框预渲染 - WinJS - GridLayout pre-rendering with grey boxes - WinJS 预渲染 nextjs getStaticProps() 给出错误:图像缺少下一个/图像所需的“src” - pre-rendering nextjs getStaticProps() giving an Error: Image is missing required "src" with next/image Next.js 带有 SSR 的应用程序未预渲染 HTML,因此网络抓取工具无法访问内容 - Next js app with SSR is not pre-rendering HTML, so web-scrapers cannot access the content 用文本预渲染画布矩形,这是不好的表现吗? - Pre-rendering a canvas rectangle with text, is this bad performance? 在实时Canvas中进行预渲染与渲染时结果奇怪 - Strange results when pre-rendering vs rendering in real-time Canvas 使用PhantomJS预渲染AngualrJS网站时“无法实例化模块ngSanitize” - “Failed to instantiate module ngSanitize” when pre-rendering AngualrJS site with PhantomJS 异步加载 vue.config.js 以预渲染元数据 - Asynchronous Loading of vue.config.js for Pre-Rendering Meta Data 我们可以使用Angular 2的服务器端预呈现来代替服务器模板引擎吗? - Can we use Angular 2's server-side pre-rendering in place of server templating engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM