开发者

How do I stop a JavaScript file from downloading twice in JavaScript?

I have two user controls and both the user controls refer a same script path:

开发者_运维技巧
<script type="text/javascript" src="test.js"></script>

then what happens when the first user controls load then test.js will download in client and when second user control loads then test.js file will download again.

How do I check to see if the JavaScript file is already downloaded so it doesn't have to be downloaded again?

If I include the JavaScript file from the server side:

Page.ClientScript.RegisterClientScriptInclude("test",  
Page.ClientScript.GetWebResourceUrl(this.GetType(), 
    "test.js"));

then how could I make sure it isn't included twice?


If the path is exactly the same, the client's browser should realize it already downloaded the file and not download it twice anyway. Can you confirm that the browser is indeed downloading it twice? If so, which browser(s)? Also check the browser cache settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜