Rails 4 and Turbolinks - Meta Tags not changing

后端 未结 4 714
遥遥无期
遥遥无期 2021-02-02 17:04

I have a Rails 4 app with turbo-links enabled, but I can\'t get the meta tags to refresh when changing the page ( not a full refresh ) . I read that the meta-tags need to be inc

相关标签:
4条回答
  • 2021-02-02 17:39

    Have a look on meta-tags gem

    "Using with pjax" section

    0 讨论(0)
  • 2021-02-02 17:45

    I extend the current turbolinks js ;)

    It will replace meta tags and canonical link!

    https://github.com/philklei/turbolinks

    0 讨论(0)
  • 2021-02-02 17:48

    It's a TurboLinks Problem

    By design, Turbolinks basically keeps the <head> of your page the same & calls the <body> of your document via ajax if it's going to remain the same (you're using the same controller / action). It's some crazy thing to maintain application performance

    Here is a good explanation of Turbolinks


    I've had a similar problem to this with Javascript, and was able to use the Jquery-Turbolinks gem to keep JS rendering

    For your meta tags, although I don't know a solution off hand, I managed to find a decent gem you might benefit from: MetaMagic. It allows you to define meta tags in the view, kind of like how the content_block facility works. This should be loaded on every http request

    0 讨论(0)
  • 2021-02-02 17:54

    How Turbolinks works

    Turbolinks is designed to keep the <head> tag the same and merely replaces the <body> tag with the contents of the requested page via an AJAX request. Since your <meta> tags are located in the <head>, they won't be changed via a Turbolinks request.

    What about SEO?

    From an SEO perspective, you don't need to worry about the <meta> tags being updated on a Turbolinks request because the search engine crawlers will always do a full page request and won't execute the Turbolinks javascript.

    From a user's perspective, the only tag in the <head> that needs to change for each request is the <title> tag, so special handling for that was built-in to Turbolinks itself.

    Will this behavior ever change?

    This "issue" has been raised and shot down a couple times, each time being declared a non-issue by DHH himself, so I wouldn't count on this behavior changing any time soon.

    See:

    • https://github.com/rails/turbolinks/issues/81
    • https://github.com/rails/turbolinks/pull/165
    0 讨论(0)
提交回复
热议问题