Attempting to update a custom CSS href, which works fine the first time, but on subsequent updates no changes occur to the page. I can see the href updating in Chrome debugger, so the event is firing, and LESS is not throwing any errors, but the colors don't update the second time around.
Here's some of the code (concatenated for readability; note I'm using VS 2010, MVC4, thus less.css extension):
<link href="/Content/themes/customizable_default.less.css" id="CustomCSS" rel="stylesheet/less" type="text/css">
<a class="ToggleButton btn-primary" CssUrl="/Content/themes/customizable_default.less.css">Default CSS</a>
<a class="ToggleButton btn-primary" CssUrl="/Content/themes/customizable_green.less.css">Green CSS</a>
<a class="ToggleButton btn-primary" CssUrl="/Content/themes/customizable_gray.less.css">Gray CSS</a>
<a class="ToggleButton btn-primary" CssUrl="/Content/themes/customizable_blue.less.css">Blue CSS</a>
<div class="ThemeBox">
<div class="ThemeCompartment1">
<h2>This is the title.</h2>
</div>
<div class="ThemeCompartment2">
<p>A bunch of copy goes here.</p>
</div>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
// choosing a template
$('.ToggleButton').click(function (e) {
$('link#CustomCSS').attr({ href: $(this).attr('CssUrl') });
localStorage.clear();
less.refresh();
});
});
</script>
Note that the stylesheet link resides in the header, so all markup is semantically correct (with the exception of the CssUrl attribute, of course). If I change the link href, then back again, the new values are not redrawn.
Example:
Click "Green CSS" button -> link href="/Content/themes/customizable_green.less.css" -> ThemeBox turns green.
Click "Red CSS" button -> link href="/Content/themes/customizable_red.less.css" -> ThemeBox turns red.
Click "Green CSS" button -> link href="/Content/themes/customizable_green.less.css" -> ThemeBox stays red.
I suspect this has something to do with .less caching, which is why I've added the localStorage.clear() call, but neither that nor less.refresh(true) have resolved the issue.
Any thoughts?