- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Reflection;
- using System.Text;
- namespace MvcCommon.Common
- {
- public static class HtmlHelpers
- {
- private static int HashCode
- {
- get { return Assembly.GetCallingAssembly().GetHashCode(); }
- }
- private static UrlHelper UrlHelper(HtmlHelper htmlHelper)
- {
- return new UrlHelper(htmlHelper.ViewContext.RequestContext);
- }
- public static HtmlString IncludeCSS(this HtmlHelper htmlHelper, params string[] urls)
- {
- var scripts = new StringBuilder();
- urls.ToList().ForEach(x=>{
- var href=UrlHelper(htmlHelper).Content(string.Format("~/Content/{0}",x))+"?"+HashCode;
- var script = string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", href);
- scripts.AppendLine(script);
- });
- return new HtmlString(scripts.ToString());
- }
- public static HtmlString IncludeJQueries(this HtmlHelper htmlHelper, params string[] urls)
- {
- var scripts = new StringBuilder();
- urls.ToList().ForEach(x=>{
- var href=UrlHelper(htmlHelper).Content(string.Format("~/Scripts/{0}",x))+"?"+HashCode;
- var script=string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>",href);
- scripts.AppendLine(script);
- });
- return new HtmlString(scripts.ToString());
- }
- }
- }
Monday, February 13, 2012
Refresh scripts and CSS in browser after deployment
To refresh browser cache after deployment,one can append the assembly hashcode to the script's url so that scripts and CSS will be fetched from server instead of cache.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment