简体   繁体   English

替代之前 </body> 标记内联Javascript

[英]Alternative to before </body> tag inline Javascript

I know inline Javascript is frowned upon and with the new on-the-fly Javascript compressors that check for idle/unused function usage and omit the unused code, it seems good practice to have all your Javascript in an external file. 我知道内联Javascript不受欢迎,并且新的即时Javascript压缩器可检查空闲/未使用的函数使用情况并省略未使用的代码,将所有Javascript放在外部文件中似乎是一种好习惯。

My question is, in situations like FOUC ( flash of unstyled content ) which usually require little snippets of code right before the closing </body> tag, is there a JQuery resolution that would serve the same purpose, but from a remote Javascript file linked in the <head> of the document? 我的问题是,在诸如FOUC (未样式化内容的闪烁)之类的情况下,通常在结束</body>标记之前仅需要几小段代码,是否有一个JQuery分辨率可以达到相同的目的,但来自远程Javascript文件在文件的<head>中?

Is $(document).ready() what your looking for? $(document).ready()是您要找的东西吗?

$(document).ready(function() {
    // anything in here will execute when the page has finished loading
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM