Using Gon and turbolinks in Rail

作者: 老码农不上班 | 来源:发表于2016-05-26 22:47 被阅读76次

Include Gon in body instead of head when using turbolinks
The reason as follow:

When you follow a link, Turbolinks automatically fetches the page, only replace in its <body>, and merges its <head>, all without incurring the cost of a full page load.

for example:
Here is a post show page. The post's content save as raw html markup tags in db column,and render it in post show page
$('div.post-content').html($.parseHTML(decodeURI(gon.con))); as this time ,the gon.con is passed by post#show action.
every post has different content = include_gon.If it was included in head tag ,all previewed post content would be merged in head. When navigation visit to another post content , the same content preview visit will be get from head and display it as a preview.

<script>
    //<![CDATA[
    something post content
    //]]>
    </script>

include gon in head tag will merge the change.
so the the correct approach is that include gon in body
Every visist , whether application visit or restoration visit, replaces the body. the content you render in page always is correspond with the post.

相关文章

网友评论

    本文标题:Using Gon and turbolinks in Rail

    本文链接:https://www.haomeiwen.com/subject/prmxdttx.html