This is a migrated thread and some comments may be shown as answers.

How to force CSS to reload using RadStyleSheetManager?

24 Answers 595 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 04 Aug 2011, 05:36 PM
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

24 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 10 Aug 2011, 02:34 PM
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.

0
Rob sherwood
Top achievements
Rank 1
answered on 10 Aug 2011, 04:58 PM
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?
0
Sean
Top achievements
Rank 2
answered on 11 Aug 2011, 08:14 PM
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.
0
Simon
Telerik team
answered on 16 Aug 2011, 11:20 AM
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.

0
Sean
Top achievements
Rank 2
answered on 16 Aug 2011, 05:51 PM
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
0
Simon
Telerik team
answered on 17 Aug 2011, 04:29 PM
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.

0
RvdGrint
Top achievements
Rank 1
answered on 20 Oct 2011, 09:19 AM
Hello Telerik,

is there already a solution to this problem?

Regards,
    Jos Meerkerk
0
Simon
Telerik team
answered on 23 Oct 2011, 05:25 PM
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
0
RvdGrint
Top achievements
Rank 1
answered on 23 Oct 2011, 07:31 PM
Simon,

Thnx. I'll wait for the Q3 release.

regards,
  Jos Meerkerk
0
RvdGrint
Top achievements
Rank 1
answered on 05 Jan 2012, 01:28 PM
I've the same problem with the RadScriptManager and my *.js files. Is there also a solutions available for this.

Regards,
  Jos
0
Simon
Telerik team
answered on 05 Jan 2012, 01:49 PM
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
0
RvdGrint
Top achievements
Rank 1
answered on 05 Jan 2012, 02:50 PM
Simon,

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

Regards,
  Jos.
0
Simon
Telerik team
answered on 05 Jan 2012, 02:59 PM
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
0
Sean
Top achievements
Rank 2
answered on 05 Jan 2012, 05:56 PM
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.
0
Simon
Telerik team
answered on 06 Jan 2012, 09:18 AM
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
0
RvdGrint
Top achievements
Rank 1
answered on 06 Jan 2012, 09:29 AM
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
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 22 Jul 2015, 05:16 PM

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.

0
Peter Filipov
Telerik team
answered on 27 Jul 2015, 11:32 AM
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
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 08 Jan 2016, 08:09 PM

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.

0
Peter Filipov
Telerik team
answered on 13 Jan 2016, 08:55 AM
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
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 21 Jul 2020, 11:26 AM

Circling back to this after (ahem) a few years, cache-busting scripts is still needed.  Can it be done by doing something like this? Basically, embed a call to a function in the ScriptReferences so the names are changed when the file changes and RadScriptManager will be forced to reload / recombine?  The syntax below is for discussion purposes and I am not going to bother doing anything further with this if the approach will not work.  Thank you.

 

 
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackTimeout="3600"><br>            <CdnSettings TelerikCdn="Enabled" /><br>            <Scripts><br>                <%--Needed for JavaScript IntelliSense in VS2010--%><br>                <%--For VS2008 replace RadScriptManager with ScriptManager--%><br>                <telerik:RadScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" Combine="True" /><br>                <telerik:RadScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" Combine="True" /><br>                <telerik:RadScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" Combine="True" /><br>                <%--this will create $ alias--%><br>                <telerik:RadScriptReference Path="~/Scripts/modernizr-custom.js" Combine="True" /><br
              <telerik:RadScriptReference Path="~/Scripts/modernizr-2.8.3.js" Combine="True" /><br><br>             
<div style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">   <%--added this to turn on and off debug and provide a wrapper for log.debug....--%><</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">> </code></span></span></div><div style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"><telerik:RadScriptReference Path="<%=Fingerprint.Tag(" />content/Content/js/toggle-debug.js") %>" Combine="True" /></code></span></span></div>

as opposed to this

              <telerik:RadScriptReference Path="~/Content/js/toggle-debug.js" Combine="True" /><br
etc.

etc.

              <telerik:RadScriptReference Path="~/Content/js/form-setup.js" Combine="True" /><br>                <%-- <telerik:RadScriptReference Path="~/Content/js/heart-beat.js" Combine="True" />--%><br>            </Scripts><br><br>        </telerik:RadScriptManager>

 

using this lovely bit from 

 

using System;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
 
public class Fingerprint
{
  public static string Tag(string rootRelativePath)
  {
    if (HttpRuntime.Cache[rootRelativePath] == null)
    {
      string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
 
      DateTime date = File.GetLastWriteTime(absolute);
      int index = rootRelativePath.LastIndexOf('/');
 
      string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
      HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
    }
 
      return HttpRuntime.Cache[rootRelativePath] as string;
  }
}
0
Peter Milchev
Telerik team
answered on 24 Jul 2020, 10:24 AM

Hello Allen,

If the issue is with the custom scripts loaded as a script reference with the Path property, then the option below might help:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" OnResolveScriptReference="RadScriptManager1_ResolveScriptReference">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        <telerik:RadScriptReference Path="~/scripts.js?cache-buster-v" />
    </Scripts>
</telerik:RadScriptManager>

protected void RadScriptManager1_ResolveScriptReference(object sender, ScriptReferenceEventArgs e)
{
    if (e.Script.Path.ToLower().EndsWith("cache-buster-v"))
    {
        e.Script.Path += "=" + DateTime.Now.ToString("yyyy-MM-dd");
    }
}

 

This way the script will be loaded with the desired query parameter:

<script src="scripts.js?cache-buster-v=2020-07-24" type="text/javascript"></script>

Regards,
Peter Milchev
Progress Telerik

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 24 Jul 2020, 06:41 PM
I will give it a whack with a big stick and report back.  Thank you.
0
Jackie
Top achievements
Rank 1
answered on 17 Mar 2021, 03:38 PM

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: [quote]Sean said: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/employee monitoring software/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.
[/quote]

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.

I faced this issue in my project. 10 years passed-still relevant. Thanks!

 

Tags
General Discussions
Asked by
Sean
Top achievements
Rank 2
Answers by
Dimitar Terziev
Telerik team
Rob sherwood
Top achievements
Rank 1
Sean
Top achievements
Rank 2
Simon
Telerik team
RvdGrint
Top achievements
Rank 1
Allen
Top achievements
Rank 2
Iron
Veteran
Peter Filipov
Telerik team
Peter Milchev
Telerik team
Jackie
Top achievements
Rank 1
Share this question
or