ASP.NET CompositeScript Path results in 404
If I use the CompositeScript feature of the ASP.NET ScriptManager/ScriptManagerProxy controls, I cannot get the Path attribute to work:
My code
<asp:ScriptManagerProxy ID="scriptProxy2" runat="server">
<CompositeScript Path="~/Includes/Javascript/Combined.js">
<Scripts>
<asp:ScriptReference Path="~/Includes/Javascript/MyFile1.js" />
<asp:ScriptReference Path="~/Includes/Javascript/MyFile2.js" />
</Scripts>
</CompositeScript>
</asp:ScriptManagerProxy>
My page gets the correct script tag in it:
<script src="../Includes/Javascript/Combined.debug.js" type="text/javascript"></script>
But of course, that file doesn't exist and so the bro开发者_高级运维wser gets a 404.
Am I missing something?
Have you specified source scripts to get combined using ScriptReference
tag - see the documentation.
EDIT: After using reflector, I discovered that if you use specify Path
attribute, the script combining does not happen - it just emits script ref to the path specified (modifying as per release/debug mode and culture (if localization is enabled)). After googling around, found that intended use of path property is to work around url limit of 1024 characters. From this MSDN documentation:
The number of script references that a CompositeScriptReference instance can contain is limited by the size of the resulting URL. The URL cannot be longer than 1024 characters.
If you have to work around this limitation, you have two options. The first option is to reduce the number of ScriptReference objects that the composite script contains. The second option is to manually combine the scripts into a single static file. In that case, you can set the Path property to the location of the static file.
I have also stumbled upon this link where there is a wealth of information in comments section. One such comment clearly states that
You can combine multiple physical script files using that feature, but we really don't recommend it as there is some server overhead related to file monitoring. What you're describing is much better handled by "building" your scripts at compile time instead of doing the combination at runtime. The feature really is for application developers who want to combine existing scripts from various components that they use in their application.
So in summary, I think that how you intend use the combine script is neither supported nor recommended. I will suggest that you use build time script combining - below resources will help you in achieving the same:
http://encosia.com/2009/05/20/automatically-minify-and-combine-javascript-in-visual-studio/
Look at mashing feature in Chirpy add-in: http://www.weirdlover.com/2010/07/18/chirpy-attains-godlike-abilities-in-version-1-0-0-4/#mash
精彩评论