我尝试使用带有Meteor 1.5 App的prerender.io。我使用npm prerender-node包
var prerenderio = Npm.require('prerender-node') .set('prerenderToken', token)
.set('protocol', protocol)
.set('host', host);
// Feed it to middleware! (app.use)
WebApp.connectHandlers.use(prerenderio);
我使用代码200登录prerender.io.Paged被缓存但页面只包含头部和空体。
为了进行测试,我添加了包meteorhacks:注入初始和插入的线在身体,它工作正常。 我想知道我的路由器是否有问题是流路由器。
我也放置
<head>
<meta charset="utf-8">
<meta name="fragment" content="!">
ALL <meta ... >
<!-- a script -->
<scripts ... >
<!-- prerenderio -->
<script> console.log(Date()); window.prerenderReady = false; </script>
</head>
为了测试,我刷新了prerender.io的缓存。 当我测试https://www.toto.com?_escaped_fragment_=
时我在客户端控制台中没有任何时间。我在prerender.io上看到了新的一行
我做了同样的测试 https://www.bing.com/webmaster/diagnostics/seo/analyzer
现在让我们看一下新的缓存行内容:
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 21 Jun 2017 20:16:33 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Cache-Control: no-cache
Content-Encoding: gzip
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/utils.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/before.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/zone.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/tracer.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/after.js?1498075872540"></script>
<script type="text/javascript" src="/packages/meteorhacks_zones/assets/reporters.js?1498075872540"></script>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="/f6675d95a01ce3ac63036505eb1ace94a68b1bb7.css?meteor_css_resource=true">
<meta charset="utf-8">
<title>Toto</title>
...
<meta name="robots" content="index, follow">
...
<!-- http referrer links -->
<meta name="referrer" content="always">
<meta name="fragment" content="!">
<!-- No resize on mobiles -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <!--320-->
<!-- a script -->
<script ... ></script>
<!-- prerenderio -->
<script> console.log(Date()); window.prerenderReady = false; </script>
</head>
<body>
<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent("%7B%22meteorRelease%22%3A%22METEOR%401.5-beta.8%22%2C%22meteorEnv%22%3A%7B%22NODE_ENV%22%3A%22production%22%2C%22TEST_METADATA%22%3A%22%7B%7D%22%7D%2C%22PUBLIC_SETTINGS%22%3A%7B%22analyticsSettings%22%3A%7B%22autorun%22%3Afalse%2C%22Mixpanel%22%3A%7B%22token%22%3A%225fc6f49885cbf2ec8d80a15c0a310399%22%2C%22people%22%3Atrue%7D%2C%22Google%20Analytics%22%3A%7B%22trackingId%22%3A%22UA-60492530-2%22%7D%7D%2C%22ga%22%3A%7B%22account%22%3A%22UA-60492530-2%22%7D%7D%2C%22ROOT_URL%22%3A%22https%3A%2F%2Fwww.Toto.com%22%2C%22ROOT_URL_PATH_PREFIX%22%3A%22%22%2C%22appId%22%3A%221yyz6nr2dyysy1rxvng3%22%2C%22autoupdateVersion%22%3A%2237dc9ce25f5e0f5f3a2253bdcb3c80166a4e83d2%22%2C%22autoupdateVersionRefreshable%22%3A%2273bc2363ca210840ec3d6947a649e3388beca5c5%22%2C%22autoupdateVersionCordova%22%3A%224b9074136556412500d12284625a4f5d81ac3f3d%22%7D"));</script>
<script type="text/javascript" src="/fef4959b1bc37d5a9c2a1c09ddcb28fd7c374f10.js?meteor_js_resource=true"></script>
</body>
</html>
在这里,我给出了整个身体内容。我没有删除任何行。
答案 0 :(得分:0)
在这里预先渲染用户。我们遇到了Prerender的问题,没有等到所有脚本都运行完成,因此计算的dom还没有完全呈现,这听起来就像你遇到的那样。为方便起见,我们使用prerender文档中描述的prerender ready标志解决了这个问题:
将它放在HTML中:
<script> window.prerenderReady = false; </script>
当我们看到window.prerenderReady设置为false时,我们将等到设置为true以保存HTML。当您的页面准备就绪时(通常在ajax调用之后)执行以下命令。
window.prerenderReady = true;