【问题标题】:Prerender IO working on localhost test but not with prod sidePrerender IO 在 localhost 测试上工作,但不适用于 prod 端
【发布时间】:2021-09-27 02:32:53
【问题描述】:

我有一个应用程序,前端是使用 VUEjs 构建的,后端是通过 Django 在 Heroku 应用程序上提供的。在本地测试时,prerender 工作正常(下载 git hub repo,在 3000 上启动本地服务器并检查站点),但是使用时

curl -A Googlebot <customsite url>

它不渲染 html,在 prerender.io 上查看日志时,我可以看到请求通过。

在 django 方面,我使用了 django-seo-js 插件,还有什么我还缺少的吗?

【问题讨论】:

    标签: prerender


    【解决方案1】:

    我意识到这个问题的例子不够详细,但我确实从 prerender.io 知识库中找到了解决问题的方法

    2018 年 5 月,Google 推出了“动态渲染”,用于向您的用户提供普通 JavaScript 并向搜索引擎提供预渲染页面。这正是我们在 Prerender.io 所做的。

    Google 为动态呈现引入的更改意味着他们将停止抓取 ?escaped_fragment= 网址,您现在可以通过直接检查其用户代理将预呈现的页面提供给 Googlebot。这听起来像是在伪装,但 Google 引入了一项政策更改,允许您通过检查其用户代理将预呈现的页面发送到 Googlebot。

    由于此动态渲染公告,我们更改了中间件,将 Googlebot 添加到直接检查的用户代理列表中。

    查看 useragent.py 文件时所说的

     # These first three should be disabled, since they support escaped 
      fragments, and
    # and leaving them enabled will penalize a website as "cloaked".
    # "Googlebot",
    # "Yahoo",
    # "bingbot",
    

    Googlebot 仍然在 django-seo-js 中被注释掉,为了解决这个问题,我不得不在 settings.py 中手动将它添加到列表中

     SEO_JS_USER_AGENTS=(
    "Googlebot",
    # "Yahoo",
    # "bingbot",
    
    "Ask Jeeves",
    "baiduspider",
    "facebookexternalhit",
    "twitterbot",
    "rogerbot",
    "linkedinbot",
    "embedly",
    "quoralink preview'",
    "showyoubot",
    "outbrain",
    "pinterest",
    "developersgoogle.com/+/web/snippet",
    )
    

    由于变量值未附加到现有列表中,我们必须将它们全部添加。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 2022-01-01
    相关资源
    最近更新 更多