Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Google font and minify

I have an @import statement in one of my css files... all my css files are bundled/minified, and apparently that is not kosher as I get an error:

run-time error CSS1019: Unexpected token, found '@import'

The import is a font from Google. What is the proper way to handle CDN in MVC4?

thanks

like image 603
aserwin Avatar asked Apr 15 '13 18:04

aserwin


People also ask

What is difference between bundling and minification?

Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads.

How to enable bundling and minification in MVC 5?

Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".

How bundling works in MVC?

Bundling and Minification are two performance improvement techniques that improves the request load time of the application. Most of the current major browsers limit the number of simultaneous connections per hostname to six. It means that at a time, all the additional requests will be queued by the browser.


1 Answers

This was embarrassingly simple...

In BundleConfig.cs :

bundles.UseCdn = true;

// bundles code

var cdnPath = "path to your resource (font in my case)";
bundles.Add(new StyleBundle("~/fonts", cdnPath));

Then in layout

@Styles.Render("~/fonts")
like image 176
aserwin Avatar answered Oct 23 '22 05:10

aserwin