Using Gon and turbolinks in Rails

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 , and merges its , 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.

1 条评论
您想说点什么吗?
jita 评论于 2017-06-30 17:31

this is helpful