I have some JS functions within the ASCX of a user control. This UC is loaded multiple times in the host page. When I do a view source, I see the JS repeated for every instance of the UC.
Is there a way I can have it load the functions only once? I would like to reduce the size of the page for better performance
-
Put the functions in a separate .js file, then add it by calling Page.ClientScript.RegisterClientScriptInclude().
You can also mark the file as an Embedded Resource, and then include it using Page.ClientScript.RegisterClientScriptResource().
Note that if you're using a ScriptManager/UpdatePanels, use ScriptManager.RegisterClientScriptInclude or .RegisterClientScriptResource so that it'll know how to add the reference correctly on a partial postback.
Terrapin : +1 because it was better than my answer - prevents multiple loads of js
0 comments:
Post a Comment