Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom css/js to MVC4 project for minification?

How do I add individual css/js files per page through the minification api?

like image 830
Iternity Avatar asked Feb 27 '12 14:02

Iternity


2 Answers

If you just want to add your own, unbundled scripts and use jquery-calls in a MVC 4 application that uses minification and bundling to include the standard libraries, here's an easy way of doing it:

By default the _Layout.chtml includes jquery and then calls

@RenderSection("scripts", required: false) 

To add your own scripts that uses jquery to the page, you can add the content for the section like this (in your view):

@section scripts {
    // At this point jquery is available. Include your own scripts here
}
like image 61
Jo Inge Arnes Avatar answered Sep 30 '22 08:09

Jo Inge Arnes


Not to sound too much like a sales man, but you could also look at RequestReduce. You don't really need to create or declare bundles instead whatever js and css you already have on your page is automatically bundled and minified. One advantage here is if different pages have different combinations of js and css, each unique combination is made into a "bundle" by RequestReduce but you dont have to manage it. Everything is cached so there is no need to worry about runtime perf costs.

like image 34
Matt Wrock Avatar answered Sep 30 '22 08:09

Matt Wrock