[CLOSED] How to include a js/css file with ResourceManager?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] How to include a js/css file with ResourceManager?

    Hi,

    Please suggest an approach to include/parse the content of a javascript file on the page using ResourceManager or otherwise. I do it rather a traditional way adding a HtmlGenericControl with the "type" and "src" attributes in the overriden page OnInit event. When a resource on the server is modified, I'd like it to be refreshed on the client on the next user request. Right now, it appears to be cached on the client. I believe I could control the cache policy using page META tags or/and Response headers on the server, but maybe there's a better and cleaner way to achieve that in Ext.Net?

    Thanks,

    Vadym
    Last edited by Daniil; Jun 20, 2012 at 9:03 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Caching depends on a browser.

    To ensure the JS will be reloaded we would recommend to use a cache buster.

    In Ext.NET context it can look like this.
    this.ResourceManager1.RegisterClientScriptInclude("myJs", "resources/js/test.js?" + DateTime.Now.Ticks);
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Caching depends on a browser.

    To ensure the JS will be reloaded we would recommend to use a cache buster.

    In Ext.NET context it can look like this.
    this.ResourceManager1.RegisterClientScriptInclude("myJs", "resources/js/test.js?" + DateTime.Now.Ticks);
    Does ResourceManager have to be defined in the markup? My pages extend a base page class without markup, where I tried to apply the approach:

    override protected void OnInit(EventArgs e)
    {
                base.OnInit(e);
    
                string baseURL = this.Request.Url.GetLeftPart(UriPartial.Authority) + (Request.ApplicationPath.EndsWith("/") ? string.Empty : Request.ApplicationPath);
    
                ResourceManager rm = new ResourceManager();
                rm.RegisterClientScriptInclude("Js1", String.Format("{0}/resources/js/js1.js?", baseURL,  DateTime.Now.Ticks));
                rm.RegisterClientScriptInclude("Js2", String.Format("{0}/resources/js/js2.js?", baseURL, DateTime.Now.Ticks));
    }
    Base URL is evaluated correctly but ResourceManager doesn't create any script includes on the page after it's rendered. What am I missing here?

    Thanks,

    Vadym
  4. #4
    Yes, you should use the ResourceManager which is already defined on the page.

    You can use
    ResourceManager.GetInstance()
    instead of referring it by ID.
  5. #5
    Quote Originally Posted by Daniil View Post
    Yes, you should use the ResourceManager which is already defined on the page.

    You can use
    ResourceManager.GetInstance()
    instead of referring it by ID.
    Thanks Daniil, I believe it works as designed. I'm curious if there's any way to control the proliferation of resource files that are now persisted in my Temporary Internet directory? Since their names are guaranteed to be unique thanks to the addition of the DateTime.Now.Ticks token, seemingly identical items replicate like avalanche to stay in cache.

    Vadym
  6. #6
    Well, you should change the cache buster only if there are any changes in the file.

    You could manage the file version and add it as a cache buster.
  7. #7
    Quote Originally Posted by Daniil View Post
    Well, you should change the cache buster only if there are any changes in the file.

    You could manage the file version and add it as a cache buster.
    Sorry, I don't quite get this. Should I change the code every time there's a change in the resource file, e.g. a stylesheet or javascript file? What I need to achieve is make the browser replace the old resource with the modified version only if there's a change. If the resource is unchanged on the server, nothing should be done.

    Thanks,

    Vadym
  8. #8
    Yes, you should monitor the changes in the file and change the cache buster code if there are any changes in the file.
  9. #9
    Quote Originally Posted by Daniil View Post
    Yes, you should monitor the changes in the file and change the cache buster code if there are any changes in the file.
    How do I make the browser purge the old versions of cached resources?

    Thanks,

    Vadym
  10. #10
    We think there is no way to programmatically force clearing of the browser cache.

    Only a user can make it clicking "Clear cache" in the browser.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] How do I include a javascript file on my page?
    By jwf in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 29, 2011, 6:08 PM
  2. HI,When the chart include
    By fancycloud in forum Open Discussions
    Replies: 0
    Last Post: Jun 27, 2011, 5:04 AM
  3. [CLOSED] How to include Ext JS Script manually
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 23, 2010, 12:24 PM
  4. [CLOSED] Include HTML in FormLayout
    By Ben in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 02, 2009, 12:14 PM
  5. jQuery Include
    By rcaunt in forum 1.x Help
    Replies: 0
    Last Post: Jul 31, 2009, 11:14 AM

Tags for this Thread

Posting Permissions