/// <summary> /// Adds a string to the URL to enforce uniqueness based on the <paramref name="uniquification"/> rule provided. /// </summary> /// <param name="url"></param> /// <param name="uniquification"></param> /// <returns></returns> public static string UniquifyUrl(string url, UrlUniquificationType uniquification = UrlUniquificationType.Never) { var uniquify = uniquification != UrlUniquificationType.Never; #if DEBUG if (uniquification == UrlUniquificationType.OnlyInDebug) { uniquify = true; uniquification = UrlUniquificationType.Always; } #endif if (uniquify) { string uniquifier; if (uniquification == UrlUniquificationType.AssemblyVersion) { var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly(); uniquifier = assembly.GetName().Version.ToString(4); } else { uniquifier = DateTime.Now.Ticks.ToString(); } url = String.Format("{0}{1}v{2}", url, url.Contains('?') ? "&" : "?", uniquifier); } return(url); }
/// <summary> /// Return a javascript file reference for use in an HTML head section. /// </summary> /// <param name="helper">The HTML helper instance that this method extends.</param> /// <param name="url">Absolute or relative URL to the script file. Relative paths will be resolved.</param> /// <param name="defer">Whether or not to defer execution of the script. Useful for files containing immediately runnable code.</param> /// <param name="uniquification">The rule for uniquifying the URL. Uniquified URLs will include the current clock ticks to help encourage the browser to always load it.</param> /// <returns></returns> public static MvcHtmlString JSFile(this HtmlHelper helper, string url, bool defer = false, UrlUniquificationType uniquification = UrlUniquificationType.Never) { return(MvcHtmlString.Create(new JsFileResource(url, defer, uniquification).GetHtmlFragment())); }
/// <summary> /// Generates a CSS link tag. /// </summary> /// <param name="helper">The HTML helper instance that this method extends.</param> /// <param name="href">Absolute or relative path to the CSS file. An app relative Href will be resolved.</param> /// <param name="media">Css file media type.</param> /// <param name="uniquification">Type of uniquification.</param> /// <returns></returns> public static MvcHtmlString CssFile(this HtmlHelper helper, string href, string media, UrlUniquificationType uniquification = UrlUniquificationType.Never) { if (string.IsNullOrEmpty(href)) { throw new ArgumentNullException("href"); } href = UrlUniquifier.UniquifyUrl(href, uniquification); return(MvcHtmlString.Create(BuildCssTag(href, media).ToString(TagRenderMode.SelfClosing))); }
/// <summary> /// Generates a CSS link tag. /// </summary> /// <param name="helper">The HTML helper instance that this method extends.</param> /// <param name="href">Absolute or relative path to the CSS file. An app relative Href will be resolved.</param> /// <param name="uniquification">Type of uniquification.</param> /// <returns></returns> public static MvcHtmlString CssFile(this HtmlHelper helper, string href, UrlUniquificationType uniquification = UrlUniquificationType.Never) { return(CssFile(helper, href, null, uniquification)); }
/// <summary> /// Adds a string to the URL to enforce uniqueness based on the <paramref name="uniquification"/> rule provided. /// </summary> /// <param name="helper"></param> /// <param name="url"></param> /// <param name="uniquification"></param> /// <returns></returns> public static string UniquifyUrl(this UrlHelper helper, string url, UrlUniquificationType uniquification = UrlUniquificationType.Never) { return(UrlUniquifier.UniquifyUrl(url, uniquification)); }
protected BasePageResource(string url, UrlUniquificationType uniquification) { Url = url; Uniquification = uniquification; }
public JsTemplateFileResource(string url, string id, UrlUniquificationType uniquification) : base(url, false, uniquification) { }
public JsFileResource(string url, bool defer, UrlUniquificationType uniquification) : base(url, uniquification) { _defer = defer; }
public CssFileResource(string url, string media, UrlUniquificationType uniquification) : base(url, uniquification) { _media = media; }
/// <summary> /// Records a JS resource that is required for the current request context. Useful for when partials are widgets that require a JS resource are used several times on a single page. /// Use the WriteRequiredJSFiles helper to write them out once (usually in a master layout). /// </summary> /// <param name="helper"></param> /// <param name="url"></param> /// <param name="media">The media type of the CSS, if any. Can be NULL.</param> /// <param name="uniquification"></param> public static MvcHtmlString RequireCss(this HtmlHelper helper, string url, string media = null, UrlUniquificationType uniquification = UrlUniquificationType.Never) { return(AddRequires(helper, KEY_CSSFILES, url, () => new CssFileResource(url, media, uniquification))); }
/// <summary> /// Records a JS resource that is required for the current request context. Useful for when partials are widgets that require a JS resource are used several times on a single page. /// Use the WriteRequiredJSFiles helper to write them out once (usually in a master layout). /// </summary> /// <param name="helper"></param> /// <param name="url"></param> /// <param name="defer"></param> /// <param name="uniquification"></param> public static MvcHtmlString RequireJS(this HtmlHelper helper, string url, bool defer = false, UrlUniquificationType uniquification = UrlUniquificationType.Never) { return(AddRequires(helper, KEY_JSFILES, url, () => new JsFileResource(url, defer, uniquification))); }