[CLOSED] ResourceManager RegisterClientScriptInclude Caching

  1. #1

    [CLOSED] ResourceManager RegisterClientScriptInclude Caching

    When I use Ext's ResourceManager to include an embedded javascript in another dll, how does caching work? How does it know whether the resource should be cached or not? When it renders the script include, what does v and h mean? When do they change?

    <script type="text/javascript" src="/LocalWebApp/App/core-js/ext.axd?v=31210&h=65705059"></script>
    Last edited by Daniil; Jan 30, 2015 at 1:44 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @jchau,

    Some answers we can find here:

    ResourceManager's GetWebResourceUrl method
    public virtual string GetWebResourceUrl(Type type, string resourceName)
    {
        if (this.Page == null)
        {
            this.Page = new Page();
        }
    
        if (!this.DesignMode && this.CleanResourceUrl && ResourceHandler.HasHandler())
        {
            string buster = (resourceName.EndsWith(".js") || resourceName.EndsWith(".css")) ? "?v=".ConcatWith(ResourceManager.CacheBuster) : "";
            if (resourceName.StartsWith(ResourceManager.ASSEMBLYSLUG))
            {
                return this.ResolveUrlLink("~/{0}/ext.axd{1}".FormatWith(resourceName.Replace(ResourceManager.ASSEMBLYSLUG, "").Replace('.', '/').ReplaceLastInstanceOf("/", "-"), buster));
            }
            else
            {
                resourceName = resourceName.Replace('.', '/').ReplaceLastInstanceOf("/", "-");
                Assembly assembly = type.Assembly;
                string hashCode = assembly.GetHashCode().ToString();
    
                if (ResourceHandler.AssembliesCache[hashCode] == null)
                {
                    ResourceHandler.AssembliesCache[hashCode] = assembly.GetName();
                    ResourceHandler.AssembliesCache["_t_" + hashCode] = type;
                }
    
                return this.ResolveUrlLink("~/{0}/ext.axd{1}{2}h={3}".FormatWith(resourceName, buster, buster.Length == 0 ? "?" : "&", hashCode));
            }
        }
                
        return HttpUtility.HtmlAttributeEncode(this.Page.ClientScript.GetWebResourceUrl(type, resourceName));
    }
    "v" - is a cache buster. It is a ResourceManager.CacheBuster which is
    Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString()
    "v" is used for caching.

    "h" is a hash code of the assembly.
    string hashCode = assembly.GetHashCode().ToString();
    "h" is used to determine a required assembly on the server to extract a resource.

    Hope this helps.
  3. #3
    Thank you! This helps alot.
  4. #4
    A follow up question. If the cache buster is based on the executing assembly, won't that mean v will always be the same because the executing assembly at that point is Ext.NET? So even if the dll where my custom resources are embedded do change, v will not.
  5. #5
    Also, I am pretty sure this is changed behavior from 2.2 to 2.5. In 2.2, it seemed to be using ASP.NET's ClientScript.GetWebResourceUrl instead. Since we upgraded, we noticed that the browser would use an older, cached version of our js files instead of pulling the latest.
  6. #6
    That is a defect, thank you for pointing out the problem.

    Created an Issue.
    https://github.com/extnet/Ext.NET/issues/646

    v2: fixed in the revision #6264 (branches/2). It goes to v2.5.4.
    v3: fixed in the revision #6265 (trunk). It goes to v3.1.0 beta.

    Please update and retest.

Similar Threads

  1. [CLOSED] Bug in RegisterClientScriptInclude version 2.3.0
    By sivsa in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 15, 2013, 10:52 AM
  2. Replies: 2
    Last Post: Oct 14, 2013, 5:46 PM
  3. Replies: 0
    Last Post: May 08, 2012, 6:15 AM
  4. [CLOSED] Caching the ResourceManager/ExtJs library
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Feb 13, 2011, 12:51 PM
  5. Replies: 2
    Last Post: May 13, 2009, 9:35 AM

Posting Permissions