简体   繁体   English

从浏览器缓存呈现的页面

[英]Cache rendered pages from browser

I have an interesting task. 我有一个有趣的任务。

I need to make page caching to database (full rendered page with executed javascript). 我需要将页面缓存到数据库(具有执行的javascript的完整渲染页面)。 I'm using symfony2 and i have an idea how I could do it: Probably I'll have to use wkhtmltopdf somehow to render the page and get the html markup after javascript is executed. 我正在使用symfony2,我对如何做到这一点有所了解:可能我将不得不以某种方式使用wkhtmltopdf渲染页面并在执行javascript之后获取html标记。 The problem is that this is just and idea and I don't know how exactly you execute this idea of mine. 问题在于这是公正的想法,我不知道您如何准确地执行我的想法。 If you have a better idea than mine I'll be very happy. 如果您有比我更好的主意,我会很高兴的。 Any help will be appreciate. 任何帮助将不胜感激。

To be more clear: Lets asume this is my page: 更清楚地说:假设这是我的页面:

<html>
    <head>
        stuff...
    </head>
    <body>
        <div id="content">

        </div>
    </body>
    <script>
        for(var i = 0; i< 3; i++) {
            $('#content').append('<p>'+i+'</p>');
        }
    </script>
</html>

and i want to get this: 我想得到这个:

<html>
    <head>
        stuff...
    </head>
    <body>
        <div id="content">
            <p>0</p>
            <p>1</p>
            <p>2</p>
        </div>
    </body>
</html>

I need this to happen without the client browser to take part(this to be generated only on the server side) 我需要在没有客户端浏览器参与的情况下进行此操作(仅在服务器端生成)

You tagged this with wkhtmltopdf, have you tried it? 您用wkhtmltopdf标记了它,您尝试过吗? On the command line execute your example page with this: 在命令行上,使用以下命令执行示例页面:

wkhtmltopdf.exe example.html example.pdf

That should pretty much work on the server without client interaction at all - the rest of the app is wiring and options (and lots and lots of coding indeed). 完全没有客户端交互的服务器上几乎应该可以工作-该应用程序的其余部分是接线和选项(确实有很多编码)。 Sometimes you need to add --javascript-delay 5000 or such for longer running javascript. 有时,您需要添加--javascript-delay 5000或类似代码,以使JavaScript的运行时间更长。 What else do you need really; 您还真正需要什么? it's hard to say. 很难说。 I would start by building a small mockup site and building ontop of that, trying out the most difficult and advanced cases that might be deal breakers. 我将从建立一个小型的模型站点开始,然后在其之上构建,尝试可能会破坏交易的最困难和最高级的案例。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM