gpt4 book ai didi

javascript - Turbolinks、Rails、后退按钮、其他来源的页脚

转载 作者:行者123 更新时间:2023-11-28 17:56:17 25 4
gpt4 key购买 nike

我对涡轮链接有疑问。当我单击浏览器中的“后退”按钮时,会附加一个页脚。

application.html.slim中:

doctype html
html
head
title
- unless content_for(:title).present?
| Some text...
- else
== yield :title
meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
= csrf_meta_tags
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
- if admin_admin_signed_in?
= stylesheet_link_tag 'cms/application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'cms/application', 'data-turbolinks-track': 'reload'

我从其他源 (application.coffee) 加载页脚:

$(document).on 'turbolinks:load', ->
$('footer').get(0).innerHTML = ''
for src in ['//other_site.com/goc/us/other_site.com/responsive.js', '//other_site.com/footer-builder.js']
s = document.createElement('script')
s.async = true
s.src = src
document.getElementsByTagName('head')[0].appendChild s

感谢您的提前关注!

最佳答案

正如@uzaif所说,对于特定的dom元素甚至类似情况下的页面,您应该将Turbolinks.clearCache()放入您的.js文件中。就我而言,我通过这种方式添加了以下代码:

application.coffee:

$(document).on 'turbolinks:load', ->
$('footer').get(0).innerHTML = ''
for src in ['//other_site.com/goc/us/other_site.com/responsive.js', '//other_site.com/footer-builder.js']
s = document.createElement('script')
s.async = true
s.src = src
document.getElementsByTagName('head')[0].appendChild s
Turbolinks.clearCache()

请记住,它会降低页面加载速度,因此请确保进行应用程序分析

关于javascript - Turbolinks、Rails、后退按钮、其他来源的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44374971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com