zoukankan      html  css  js  c++  java
  • ASP.Net MVC(4) 之js css引用与压缩

    资源引用

    可以用即可以直接使用“~”来表示根目录。

    引入js

    <script src="~/Areas/OrderManage/JS/Form.js"></script>

    引入css

    <link href="~/Content/uploadify/uploadify.css" rel="stylesheet" />

    引用img路径也可以如此

     <img src="~/Images/index/banner_1.jpg" alt="" title="" /></a>

    对样式表和脚本的优化压缩

    在MVC4.0中System.Web.Optimization包含了JsMinify和CssMinify,不要小看这两个类,虽然公开的方法就两个,可以把脚本编译,压缩成最小的内容。

    按照上述方法是用Scripts和Styles将脚本和样式表引入页面时,无需修改任何代码就可以将脚本和样式表编译压缩输入到客户端,这样不仅可以有效的增加JSHack的难度以及降低文件的大小。为了达到这个目的,我们只需要将BundleTable中的一个属性设置为true即可,代码如下:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Configuration;
     4 using System.Data.Entity;
     5 using System.Data.Entity.Infrastructure;
     6 using System.Linq;
     7 using System.Web;
     8 using System.Web.Http;
     9 using System.Web.Mvc;
    10 using System.Web.Optimization;
    11 using System.Web.Routing;
    12 namespace MVC4
    13 {
    14     // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    15     // visit http://go.microsoft.com/?LinkId=9394801
    16     public class MvcApplication : System.Web.HttpApplication
    17     {
    18         protected void Application_Start()
    19         {
    20             AreaRegistration.RegisterAllAreas();
    21             
    22             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    23             RouteConfig.RegisterRoutes(RouteTable.Routes);
    24             //设置为true
    25             BundleTable.EnableOptimizations = true;
    26             BundleConfig.RegisterBundles(BundleTable.Bundles);
    27         }
    28     }
    29 }
  • 相关阅读:
    C++右值引用的参考
    U3D 文档 GPU INSTANCING
    UNITY statistic中的 SetPass和Batches
    时间复杂度
    转,数组遍历的三种方式
    bug纪录:PhotonServer-14052: 17:14:09.033
    关于.net standard 与 .net core, net framework
    【转】未能加载文件或程序集或它的某一个依赖项,系统找不到指定的文件
    C# 计时函数精度测试
    一张图看懂dex
  • 原文地址:https://www.cnblogs.com/yx007/p/5688644.html
Copyright © 2011-2022 走看看