头js加载javascript文件的问题

头js加载javascript文件的问题,javascript,refresh,minify,head.js,Javascript,Refresh,Minify,Head.js,我正在使用headjs并行加载我的javascript文件。我将headjs添加到我的head中,然后使用head.js(“path/to/file/my.js”)但是当我加载我的网页时,脚本丢失了。只有在刷新几次之后,整个脚本才能正常工作。为什么我需要刷新它以使其工作?如有任何建议,将不胜感激 由于脚本是异步加载的,因此不能立即使用。刷新页面后,它将在缓存中找到脚本,因此它将及时加载任何有时需要它的代码 对于需要脚本的任何代码,请使用ready方法: head.ready(function()

我正在使用headjs并行加载我的javascript文件。我将headjs添加到我的head中,然后使用
head.js(“path/to/file/my.js”)但是当我加载我的网页时,脚本丢失了。只有在刷新几次之后,整个脚本才能正常工作。为什么我需要刷新它以使其工作?如有任何建议,将不胜感激

由于脚本是异步加载的,因此不能立即使用。刷新页面后,它将在缓存中找到脚本,因此它将及时加载任何有时需要它的代码

对于需要脚本的任何代码,请使用
ready
方法:

head.ready(function() {
  // any code that needs the script to be loaded first
});

由于脚本是异步加载的,因此不能立即使用它。刷新页面后,它将在缓存中找到脚本,因此它将及时加载任何有时需要它的代码

对于需要脚本的任何代码,请使用
ready
方法:

head.ready(function() {
  // any code that needs the script to be loaded first
});

另一种方法是标记库,然后在加载脚本时获取就绪事件。阅读更多有关标记脚本的内容

head.ready("your", function() {

});

head.js(
   {jquery: "http://http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"},
   {tools: "http://cnd.jquerytools.org/1.2.5/tiny/jquery.tools.min"},
   {your: "http://a.heavy.library/we/dont/want/to/wait/for.js"},

   // label is optional
   "http://can.be.mixed/with/unlabeled/files.js"
);

另一种方法是标记库,然后在加载脚本时获取就绪事件。阅读更多有关标记脚本的内容

head.ready("your", function() {

});

head.js(
   {jquery: "http://http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"},
   {tools: "http://cnd.jquerytools.org/1.2.5/tiny/jquery.tools.min"},
   {your: "http://a.heavy.library/we/dont/want/to/wait/for.js"},

   // label is optional
   "http://can.be.mixed/with/unlabeled/files.js"
);