Meh Man
Meh Man

Reputation: 473

What is best solution for update version of css file

I usually after css modification, change the version of css file in master. then i must upload css file and master file. is there any solution to change css version without need to upload master.

<link rel="stylesheet" href="<%=ResolveUrl("~/themes/default/style.css?v2") %>" type="text/css"/>

i am using asp.net.

Upvotes: 3

Views: 1725

Answers (2)

Johannes Kommer
Johannes Kommer

Reputation: 6451

Seeing how you do not want to change anything but the CSS file itself you could write a custom method which wraps ResolveURL and appends the last modified date of the css file in a set format (i.e. MMddyyhhmmss). This would automatically update whenever the file gets changed.

Something along the lines of:

    <link href="<%= VersionCssUrl("~/Styles/Site.css") %>" rel="stylesheet" type="text/css" />

C#:

    public string VersionCssUrl(string url)
    {
        // Get physical path.
        var path = HttpContext.Current.Server.MapPath(url);

        return String.Format("{0}?{1}", 
            ResolveUrl(url), 
            File.GetLastWriteTime(path).ToString("MMddyyhhmmss"));
    }

Alternatively, it might be worth looking into any of these:

Upvotes: 4

TJB
TJB

Reputation: 13497

There are lots of automated solutions for this now-a-days

Cassette @ http://getcassette.net/ is open source

They have installation via Nuget which simplifies the configuration / setup.

Upvotes: 1

Related Questions