Asp.net mvc3 html/CSS/JS compression merge-continuous update

Source: Internet
Author: User

1. CSS/JS compression:

The merge below uses the combres component. I don't need this implementation here. We recommend a CSS/JS editor that can be edited like CS/aspx in.

Name: chirpy

Website: http://chirpy.codeplex.com/

English Introduction: http://www.weirdlover.com/2011/03/03/chirpy-v2/

Description: Implements CSS/JS file editing like CS/aspx to edit uncompressed CSS/JS and compressed to min.css/Js. You only need to name the CSS/JS name according to the set rules. chirpy will automatically generate a min compressed version for the file and display it in submode. Truth:

Usage: first download it from codeplex. If vs2010 is installed, you can directly install the component, restart vs2010, and enable the tool-> option:

In the green box, you can customize uncompressed file names. There are also JavaScript settings on the left and many other functions! Now you only need to change CSS/js.to yui.css/Yui. js. Here, Yui uses Yahoo compressor for compression. You can select hybird... on the right.

2. Combine CSS/JS and use combres

Name: combres

Website: http://nuget.codeplex.com/releases/view/64974

English Introduction: http://www.codeproject.com/KB/aspnet/combres2.aspx

Description: If mvc3 needs to be used in conjunction with the documentation of the website, Asp.net and MVC2 are used by default in English. The configuration and use process of mvc3 are somewhat different. You can view the introduction in English for different purposes. Here I will introduce the use of mvc3. The template engine is razor.

Usage:

(1) download combres and decompress it. You can also directly useNugetFunction, I will not download it here;

(2) create an mvc3 project, open vs2010, view-> other Windows-> package
Manager Console;

(3) InputInstall-Package
Combres. MVC,
Automatic Installation of combres

 
(4) After the installation is complete, the app_data/combres. XML will be automatically generated. This is the configuration of the compressed/merged files. The specific configuration can be described in English. Here is my configuration example:

   <?xml version="1.0" encoding="utf-8" ?><combres xmlns="urn:combres">  <resourceSets url="~/combres.axd" defaultDuration="30"                                defaultVersion="auto"                                defaultDebugEnabled="auto" >    <resourceSet name="siteBaseCss" type="css">      <resource path="~/Content/themes/base/jquery.ui.accordion.css" />      <resource path="~/Content/themes/base/jquery.ui.autocomplete.css" />      <resource path="~/Content/themes/base/jquery.ui.base.css" />      <resource path="~/Content/themes/base/jquery.ui.button.css" />      <resource path="~/Content/themes/base/jquery.ui.core.css" />      <resource path="~/Content/themes/base/jquery.ui.datepicker.css" />      <resource path="~/Content/themes/base/jquery.ui.dialog.css" />      <resource path="~/Content/themes/base/jquery.ui.progressbar.css" />      <resource path="~/Content/themes/base/jquery.ui.resizable.css" />      <resource path="~/Content/themes/base/jquery.ui.selectable.css" />      <resource path="~/Content/themes/base/jquery.ui.slider.css" />      <resource path="~/Content/themes/base/jquery.ui.tabs.css" />      <resource path="~/Content/themes/base/jquery.ui.theme.css" />    </resourceSet>    <resourceSet name="siteCss" type="css">      <resource path="~/Content/Site.css" />    </resourceSet>    <resourceSet name="siteJs" type="js">      <resource path="~/Scripts/jquery-1.5.1.js" />      <resource path="~/Scripts/jquery-ui-1.8.11.js" />    </resourceSet>  </resourceSets></combres>

(5) delete appstart_combres.cs and remove webactivetor references.

(6) Open the reference to add using combres; to global. asax. Add

routes.AddCombresRoute("Combres");

(7) The page is used as follows:

@using Combres.Mvc;<!DOCTYPE html>

3. Delete spaces in HTML

1. a class that references a network to delete spaces:

    public class WhiteSpaceStream : Stream    {        private readonly Stream m_sink;        private static readonly Regex m_regex = new Regex(@"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}");        public WhiteSpaceStream(Stream sink)        {            m_sink = sink;        }        public override bool CanRead        {            get { return true; }        }        public override bool CanSeek        {            get { return true; }        }        public override bool CanWrite        {            get { return true; }        }        public override void Flush()        {            m_sink.Flush();        }        public override long Length        {            get { return 0; }        }        public override long Position { get; set; }        public override int Read(byte[] buffer, int offset, int count)        {            return m_sink.Read(buffer, offset, count);        }        public override long Seek(long offset, SeekOrigin origin)        {            return m_sink.Seek(offset, origin);        }        public override void SetLength(long value)        {            m_sink.SetLength(value);        }        public override void Close()        {            m_sink.Close();        }        public override void Write(byte[] buffer, int offset, int count)        {            byte[] data = new byte[count];            Buffer.BlockCopy(buffer, offset, data, 0, count);            string text =UTF8Encoding.UTF8.GetString(buffer);            text = m_regex.Replace(text, string.Empty);            byte[] outdata = UTF8Encoding.UTF8.GetBytes(text);            m_sink.Write(outdata, 0, outdata.GetLength(0));        }    }

2. customize an actionfilterattribute

    public class WhiteSpaceFilterAttribute : ActionFilterAttribute    {        public override void OnActionExecuting(ActionExecutingContext filterContext)        {            filterContext.HttpContext.Response.Filter = new WhiteSpaceStream(filterContext.HttpContext.Response.Filter);        }    }

3. Place the space to be deleted plus

    [WhiteSpaceFilterAttribute ]   public ActionResult Index(string id)    {      return View();    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.