0

I have several javascript files and I'd like to combine them into one file but only when the page is rendered, and still keep my files separate because it's easier to code with multiple files than one giant one.

How do I do this? I saw some tutorials on how to do it but they're dated. I'm using VS 2012 and I was wondering if there's a newer way.

Thanks.

2 Answers 2

2

Since you mentioned VS2012, check Bundling and Minification.

Sign up to request clarification or add additional context in comments.

2 Comments

ah yes, that's the feature I was looking for. Where do we put the line BundleTable.EnableOptimizations = true; ?
It seems that it should be somewhere in Global.asax, check asp.net/web-forms/videos/aspnet-vnext/…
1

Use ScriptManager's thingy called "CompositeScript". Probably the easiest way to do this.

http://msdn.microsoft.com/en-us/library/cc488552(v=vs.90).aspx

You can always implement your custom solution though, if this doesn't fit your needs for whatever reason.

8 Comments

I get 'ScriptManager' is not a known element. I've added the ajaxcontroltoolkit.dll file to the bin directory but it's not working. any suggestion?
ScriptManager is a regular control since version 3.5, you don't need ajaxcontroltoolkit in order to work with it. There's another similar control called ToolkitScriptManager you're probably confusing this one with. Please verify that you have a reference in your project to System.Web.Extensions
This seems too much trouble; I'm going with the VS2012 bundling option. Thanks for your answer.
Referencing ajaxcontroltoolkit.dll is ok, while referencing a regular .net dll is "too much trouble"? Furthermore, you choose a path using a RC version of .NET framework, where you may encounter problems with availability etc. Well, good luck with that...
Well I'm looking to avoid dependencies.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.