html5boiler 板 + jquery mobile = 脚本加载两次
我正在开发一个基于 jquery 的实验性移动应用程序,使用 html5 样板 作为 html 等的基础。
基本上到目前为止我所做的就是:
- 下载并提取 html5 样板,然后在浏览器中查看它。确保脚本/样式正确加载。准备好出发了。
- 添加 jquery mobile(cdn 托管完整版本 1.0 [今天发布?马上!])
- 添加
$(document).ready(function () { console.log('ready'); });
- 重新加载。 'ready' 输出两次.. 第二次稍有延迟后..
- wtf bbq 和 chrome 检查器中的这种检查情况.. 请注意,所有 javascript 文件似乎都加载了两次。
- 从头开始重新启动,在浏览器中提取 h5bp 加载,特别注意脚本加载一次。添加文档就绪处理程序,观察“就绪”的一个输出。
- 添加jquery mobile观察脚本加载一次。
- 将所有脚本移至标记中。脚本加载一次。
有人知道发生了什么事吗?重现这个应该很容易,只需提取 h5bp 并将 jquery mobile 添加到底部的脚本部分,突然所有脚本都加载两次。将所有这些脚本移至 Modernizr 下方(或之前)的 head 标签中,这种情况将不再发生。
谢谢
I am working on an experimental jquery mobile based app using html5 boilerplate as a base for html and such.
Basically all I have done thus far is:
- Download and extract html5 boilerplate, and view it in the browser. Make sure scripts/styles are loading properly. Good ready to go.
- Add jquery mobile (cdn hosted full version 1.0 [released today? right on!])
- Add
$(document).ready(function () { console.log('ready'); });
- Reload. 'ready' is output twice.. the second one after a slight delay..
- wtf bbq and such inspect situation in chrome inspector.. notice all javascript files seem to be loading twice.
- Restart from scratch, extract h5bp load in browser, note in particular that scripts load once. Add document ready handler, observe one output of 'ready'.
- Add jquery mobile observe scripts loading once.
- Move all scripts into the tag. Scripts load once.
Anyone have any idea what is going on? It should be pretty easy to reproduce this, just extract h5bp and add jquery mobile to the scripts section at the bottom and suddenly the scripts all are loading twice. Move all those scripts into the head tag beneath (or before) modernizr and this no longer occurs.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Modernizr 使用 YepNope 加载脚本。如果您在这里查看问题: https://github.com/SlexAxton/yepnope .js/issues/10
你会看到脚本被故意加载两次:
http://yepnopejs.com 主页上也提到了这一点。只需转到那里并向下滚动到
我在我的开发工具中看到两个请求,为什么它会加载所有内容两次?
Modernizr uses YepNope to load scripts. If you take a look at the issue here: https://github.com/SlexAxton/yepnope.js/issues/10
you'll see that scripts are intentionally loaded twice:
There's also mention of this on the http://yepnopejs.com home page. Just go there and scroll down to
I'm seeing two requests in my dev tools, why is it loading everything twice?
将
放入
将解决此问题。
Putting your
<script>document.ready()</script>
in<head></head>
will fix this problem.你在使用 $(document).ready() 吗?
遇到了同样的问题,并且非常沮丧,注意到如果我将所有 JS 移到文档的头部,它就可以正常工作。当我将所有内容切换为使用 pageinit 时,JS 就开始在它所属的页面底部正常工作。
示例:
更多详细信息请访问:http://jquerymobile.com/demos/1.0/文档/api/events.html
Are you using $(document).ready()??
Ran into this same issue and was frustrated to no end, noticed that if I moved all the JS to the head of the document it worked fine. When I switched everything to use pageinit started working properly with JS at bottom of page where it belongs.
example:
further details available at: http://jquerymobile.com/demos/1.0/docs/api/events.html
我尝试在基本的 html 页面上添加 jQuery 和 jQuery Mobile,似乎也发生了这样的情况。所以不要认为它与 h5bp 相关。你能尝试去掉 h5bp 的东西并重新加载吗?
I tried adding jQuery and jQuery Mobile on a basic html page, it seems to happen like this as well. So don't think it's h5bp related. Could you try strip out the h5bp stuff and load again?
确保你的根 div 是这样的......
Make sure your root div is like this...