![](/img/trans.png)
[英]why does javascript load before html? i put the body's content before the script but it still does'nt work
[英]Why does script file that's loaded before jQuery still work?
我打算從Rails應用程序通過CDN加載jQuery。 不幸的是我無法顯示代碼,但我會盡力解釋。 代碼設置如下:
在布局中,在關閉body標簽之前:
= javascript_include_tag "main_web"
main_web.js:
//= require jquery
//= require page_script
現在我要做的是
在布局中
= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"
= javascript_include_tag "main_web"
在main_web.js中,我將刪除jQuery依賴項
//=require page_script
我做到了,現在我有了一個瀑布,看起來像這樣:
我想確保在實施該更改時,沒有任何訪問者的瀏覽器會嘗試在加載jQuery之前執行main_script。
無法100%確定腳本的位置或它們在頁面上的呈現方式,但是從標記加載的JavaScript文件會順序執行。 因此,如果頁面中有兩個腳本文件:
<script src="filea.js"></script>
<script src="fileb.js"></script>
filea.js將在fileb.js之前執行
您的示例中可能會出現這種情況,但是我不確定是否會加載它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.