1

This is a really strange one. I am trying to add a cache value to my css stylesheet references in order to invalidate the http header caching I have set. I have the following code:

<link href="/css/Continuity2/layout.css?cache=<%=Global.CACHE_KEY %>" rel="stylesheet" type="text/css" />

The above is rendered as follows and does not seem to be picking up the inline code:

<link href="/css/Continuity2/layout.css?cache=&lt;%=Global.CACHE_KEY %>" rel="stylesheet" type="text/css" />

The even stranger thing is, I have the following code for my javascript references:

<script type="text/javascript" src="/js/ajaxhelper.js?cache=<%=Global.CACHE_KEY %>"></script>

And this references as expected:

<script type="text/javascript" src="/js/ajaxhelper.js?cache=70BE31E0-E694-45ff-A920-D6564DA2FB79"></script>

Has anyone any idea why on earth this would happen?

1 Answer 1

2

<link> tags inside a <head> tag are converted into HtmlLink objects.

You can resolve the issue either by setting the property value programmatically from your code behind, or by using a control adapter.

It would probably also work if you moved the tag outside of your head section, although that can have an effect on the way your page is rendered (potential flashes, etc after the CSS is loaded).

I should also add that using a query string on static files to force versioning is usually not an ideal solution, because it prevents the high performance kernel mode HTTP driver (http.sys) from caching the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. What is a better approach to the querystring for static file versioning?
Change the name of the file or the folder that contains it, and have a control that automatically picks up the files that are there, so you don't have to also change your code. That way, you can also set far-future cache expiration dates. In case it helps, I talk about this and related issues in my book: Ultra-Fast ASP.NET.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.