C# 클래스 WebApplication.Mvc5.BowerBundlerHelper

This class contains extention methods to provide a the inclusings of CSS and JavaScript files in your views 1) @Html.HtmlCssCached("bundleName") is equivalent to @Styles.Render("~/Content/bundleName") 2) @Html.HtmlScriptsCached("bundleName") is equivalent to @Scripts.Render("~/bundles/bundleName") Whether it delivers individual files or the single minfied file that Grunt produced is defined by whether the code was compiled in DEBUG mode or not. This can be overridden on each method by the optional 'forceState' parameter. Both these methods have some small limitations: 1. These methods can do searches for files, e.g. ~/Scripts/*.js, or ~/Scripts/*/*.js However it does not support Grunt/Gulp's /**/ search all directories and subdirectories feature. It is something that could be implemented, but I left it out for now. It throws an NotImplementedException if found 2. I suspect that the .NET search and the Grunt/Gulp search might have slightly different rules. see the Note under Remarks about a search like *.js https://msdn.microsoft.com/en-us/library/wz42302f%28v=vs.110%29.aspx 3. BundlerHelper has the same problem (feature) as BundleConfig. If you change or add files to the settings.json file then you need to rebuild your application because HtmlCssCached and HtmlCssCached deliver from a static cache. You can turn off caching by setting the forceState parameter in each methods to true. Finally it is very tempting to add comments to the settings.json file. While Json.Net handles comments Grunt doesn't, and fails silently!
파일 보기 프로젝트 열기: JonPSmith/MvcUsingBower

공개 메소드들

메소드 설명
AddCacheBusterCached ( this helper, string relFilePath, string precalculatedCacheBuster = null ) : string

This can be applied to any static file, e.g. an image, and it adds a cachebuster value to the file access. The format of how the cacheBuster value is added is controlled by the 'StaticFileCaching' in the BunderForBower.json file. If a checksum is calculated for the file it is cached locally, as it can take some time on large files.

GetChecksumBasedOnFileContent ( string absFilePath ) : string

This calculate a checksum based on the content of the file. It actually uses a SHA256 Hash. This is heplful as it allows you to use the general Grunt 'build'command, which rebuilds everything, and the cache buster won't change unless the content changes.

HtmlCssCached ( this helper, string bundleName, bool forceState = null ) : System.Web.Mvc.MvcHtmlString

This returns the CSS links using caching if forceState is null Note: this assumes that the CSS minified file is in the directory "~/css/"

HtmlScriptsCached ( this helper, string bundleName, bool forceState = null ) : System.Web.Mvc.MvcHtmlString

This returns the script includes for a specific group using caching if forceState is null Note: this assumes that the JavaScript minified file is in the directory "~/js/"

비공개 메소드들

메소드 설명
CreateHtmlIncludes ( this helper, string bundleName, CssOrJs cssOrJs, bool forceState = null ) : System.Web.Mvc.MvcHtmlString

This returns the html to include either CSS or JavaScript files

GetBundlerForBowerCached ( HtmlHelper helper ) : BundlerForBower
GetChecksumFromRelPath ( string fileRelPath ) : string

메소드 상세

AddCacheBusterCached() 공개 정적인 메소드

This can be applied to any static file, e.g. an image, and it adds a cachebuster value to the file access. The format of how the cacheBuster value is added is controlled by the 'StaticFileCaching' in the BunderForBower.json file. If a checksum is calculated for the file it is cached locally, as it can take some time on large files.
public static AddCacheBusterCached ( this helper, string relFilePath, string precalculatedCacheBuster = null ) : string
helper this
relFilePath string The relative path to the file inside the web application
precalculatedCacheBuster string if null then a cachebusting value is calculated based on the file content (cached locally for performance) /// If you provide a precalculated a cachebuster value, say created at build time, then that will be used instead
리턴 string

GetChecksumBasedOnFileContent() 공개 정적인 메소드

This calculate a checksum based on the content of the file. It actually uses a SHA256 Hash. This is heplful as it allows you to use the general Grunt 'build'command, which rebuilds everything, and the cache buster won't change unless the content changes.
public static GetChecksumBasedOnFileContent ( string absFilePath ) : string
absFilePath string
리턴 string

HtmlCssCached() 공개 정적인 메소드

This returns the CSS links using caching if forceState is null Note: this assumes that the CSS minified file is in the directory "~/css/"
public static HtmlCssCached ( this helper, string bundleName, bool forceState = null ) : System.Web.Mvc.MvcHtmlString
helper this
bundleName string The name of the setting.json property containing the list of Css file to include. /// defaults to main Css file
forceState bool if not null then true forces into debug state and false forces production state
리턴 System.Web.Mvc.MvcHtmlString

HtmlScriptsCached() 공개 정적인 메소드

This returns the script includes for a specific group using caching if forceState is null Note: this assumes that the JavaScript minified file is in the directory "~/js/"
public static HtmlScriptsCached ( this helper, string bundleName, bool forceState = null ) : System.Web.Mvc.MvcHtmlString
helper this
bundleName string The name of the setting.json property containing the list of JavaScript file to include. /// defaults to main js file
forceState bool if not null then true forces into debug state and false forces production state
리턴 System.Web.Mvc.MvcHtmlString