How to force CSS to reload using RadStyleSheetManager?

21 posts, 0 answers
  1. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 04 Aug 2011 Link to this post

    Hi,

    It is common practice to do something such as this:

    <link rel="stylesheet" type="text/css" href="../Content/Dashboard/Dashboard.css?t=<%= DateTime.Now.Ticks %>" />

    This is for development purposes, and would be converted to something like ?v=[Version Number] for releases. This is to force browsers to reload CSS instead of using cached versions.

    If I attempt to use the same syntax inside of RadStyleSheetManager I am told I am using illegal characters. Does Telerik's control support something like this?

    Thanks

    Sean
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 10 Aug 2011 Link to this post

    Hello Sean,

    In case you want to load custom styles using our RadStyleSheetManager, please refer to the following help article.

    Best wishes,
    Dimitar Terziev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob sherwood
    Rob sherwood avatar
    3 posts
    Member since:
    Jun 2009

    Posted 10 Aug 2011 Link to this post

    Hi Dimitar,

    That link doesn't seem to provide a solution to the original question. It is also outdated and does not apply to the most recent Telerik builds (that support directly including your own CSS with a reference to the directory in the web.config via Telerik.Web.UI.StyleSheetFolders..

    I think another way to phrase Sean's question would be: How can I avoid having to rebuild the solution every time I make a change to CSS included via the RadStyleSheetManager? Is there a way to disable caching?
  5. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 11 Aug 2011 Link to this post

    It's more than just rebuilding the solution, but I thank you both for the responses.

    If I push a build out live, a customer installs this web application, and their browser caches the CSS file, I need a means of informing their browser that the CSS file is out of date.

    See this thread: http://stackoverflow.com/questions/101125/force-browser-to-use-new-css

    I experience this issue in my project. If I do not clear the browsers cache, or generate unique paths to the css file, then the browser will continue to use the old CSS version until some arbitrary time has passed.
  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 16 Aug 2011 Link to this post

    Hi Sean,

    If the references to the style sheets in the RadStyleSheetManager are to embedded resources, then simply rebuilding the assembly containing these resources will cause another URL to be generated, which will effectively force the browser to request the resources anew.

    What kind of the resources you are referencing in RSSM - embedded or external?

    Kind regards,
    Simon
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  7. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 16 Aug 2011 Link to this post

    Hi Telerik,

    The files I am working on, I believe, are external resources. The stylesheets are located at MyProject/Content/
    I did a quick Google attempting to compare the pros/cons of embedded vs external style sheets, but didn't come up with anything.


            <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" Runat="server">
                <StyleSheets>
                    <telerik:StyleSheetReference Path="~/Content/Dashboard/Site.css" />
                </StyleSheets>
            </telerik:RadStyleSheetManager>
     
    <link rel="stylesheet" type="text/css" href="../Content/Site.css?t=<%= DateTime.Now.Ticks %>" />

    In my project's Web Properties, I have it set to NOT use the Visual Studio Development Server. I am targeting a Local IIS Web Server and overriding the application root URL. I'm not sure if this has any barring on Telerik controls, but there are differences between the two. 

    Is this something I should be experiencing? It sounds like it's something on my end.

    Thanks,

    Sean
  8. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 17 Aug 2011 Link to this post

    Hello Sean,

    Thank you for the clarification.

    Currently RadStyleSheetManager does not provide any means of invalidating the cache for externally combined style sheets. The only time the URL is invalidated is when the Telerik.Web.UI assembly is updated, i.e. its version changes. The only way to avoid the problem is to disable cache in the browser during development.

    The web server is unrelated to the actual problem - the URLs do not change when the external style sheets are modified. The web server works as it is configured and the rest is up to the browser and there is nothing wrong with them.

    We will address this issue in the upcoming weeks. Please excuse us for the caused inconvenience.

    Regards,
    Simon
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  9. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 20 Oct 2011 Link to this post

    Hello Telerik,

    is there already a solution to this problem?

    Regards,
        Jos Meerkerk
  10. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 23 Oct 2011 Link to this post

    Hello Jos,

    Yes, an automatic cache buster, that invalidates the URL whenever the last modified date of an external style sheet reference is changed, has been implemented after Q2 2011 SP1 (version 2011.2.915).

    So you have two options: either use an internal build or wait for the Q3 2011 release for an official version.

    Regards,
    Simon
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  11. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 23 Oct 2011 Link to this post

    Simon,

    Thnx. I'll wait for the Q3 release.

    regards,
      Jos Meerkerk
  12. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 05 Jan 2012 Link to this post

    I've the same problem with the RadScriptManager and my *.js files. Is there also a solutions available for this.

    Regards,
      Jos
  13. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 05 Jan 2012 Link to this post

    Hi Jos,

    RadScriptManager inherits from ScriptManager and serving external scripts is in the codebase of the latter. Unfortunately no 'cache buster' is implemented by SM. If are able to override the part of workflow of SM, which works with external scripts, we will be able to add a 'cache buster'. This however may happen in future versions.

    Regards,
    Simon
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  14. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 05 Jan 2012 Link to this post

    Simon,

    is there an other way to force that always the latetst script files are used?

    Regards,
      Jos.
  15. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 05 Jan 2012 Link to this post

    Hi Jos,

    As far as I know there is no convenient way to do this. One thing you can do is to version the external JavaScript files, e.g. script_v1.js and increment the version whenever you need to force the new version. Of course this will require to change the name in the place you add the script to (Rad)ScriptManager.

    I hope this helps.

    Regards,
    Simon
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  16. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 05 Jan 2012 Link to this post

    Jos,

    Just thought I would chime in here -- Our solution does currently implement a solution for this which may or may not be useful to you.

    public static class VersionManager
    {
        private static string _urlVersion = null;
        public static string UrlVersion
        {
            get
            {
                if (_urlVersion == null)
                {
                    string version = HttpContext.Current.IsDebuggingEnabled ? DateTime.Now.ToString() : FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
                    _urlVersion = "?v=" + version;
                }
     
                return _urlVersion;
            }
        }
    }
     
    And it's usage is:

    <link rel="stylesheet" type="text/css" href="../Content/Dashboard/CustomTooltip.css<%=VersionManager.UrlVersion%>" />

    You'll need to import the namespace into your .aspx file, though:

    <%@ Import Namespace="CableSolve.Web.Controllers.Managers" %>

    What this does is appends to the end of a path either the current Date/Time in Debug mode, or the solution's version in Release mode. What this means for you as a developer is that in Debug mode this file will not be able to be cached. Then, out in the wild, every time you release a new version of your product -- the old cache will be replaced with new, but not again until a new version.

    I would still recc. keeping your RadStyleSheetManager on the page, though, as it does do additional work in condensing all the files into one request.
  17. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 06 Jan 2012 Link to this post

    Hello Sean,

    That is a good solution. Thank you for sharing it with us and the community.

    Regards,
    Simon
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  18. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 06 Jan 2012 Link to this post

    This doesn't work in the RadScriptManager and I need to use the ScriptManager because some scripts are not loaded correct if de not use the scriptmanager.

    Regards,
      Jos
  19. Allen
    Allen avatar
    50 posts
    Member since:
    Mar 2011

    Posted 22 Jul 2015 in reply to Simon Link to this post

    I am sorry but these manager tools should automatically implement cache-busting for css and javascript alike if the user wants it.

     

    The solution provided by Sean assumes css files are referenced in Link statements.  

    <link rel="stylesheet" type="text/css"href="../Content/Dashboard/CustomTooltip.css<%=VersionManager.UrlVersion%>" /> 

    As far as I can tell, Rad StyleSheetManager wants  the relevant css files entered as properties for the control and not as link statements like this, so how do we reconcile these two approaches?   A similar dilemma occurs for js files.  Both Telerik controls for script and stylesheet management should implement cache-busting or cache-expiry setting or whatever.

  20. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 27 Jul 2015 Link to this post

    Hello Allen,

    Please log your suggestion in our feedback portal and vote for it.

    Regards,
    Peter Filipov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  21. Allen
    Allen avatar
    50 posts
    Member since:
    Mar 2011

    Posted 08 Jan in reply to Simon Link to this post

    So do I have to make any changes in my code to tell the RadStyleSheetManager to bust the cache and reload if the css file mod datetime changes?  What about RadScriptManager for js?  A more complete example would be helpful.

    Thank you.

  22. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 13 Jan Link to this post

    Hello Allen,

    This feature is not supported by the control. In case that you want to reload the scripts you could add them as a embedded resource and on every build of the project where they resides the links to them will be changed. 

    Regards,
    Peter Filipov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017