Add url parameter to css file in asp themes folder

前端 未结 3 2024
抹茶落季
抹茶落季 2021-01-12 20:21

I have written a bit of code that helps with versioning of js files. Essentially it spins around the current script manager and appends the javascript file path with an md5

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 21:11

    I am facing one issue that it is repeating css entry in html markup on every postback. for example, I have newabc.css. the code will change it to newabc.css?v=1. if I see html source after 5 postback, it will have 5 "newabc.css?v=1". so I added link.EnableViewState = False, it works fine but is it actually needed?

        Dim link As HtmlLink = Nothing
    
        For Each c As Control In Page.Header.Controls
            If TypeOf c Is HtmlLink Then
                link = TryCast(c, HtmlLink)
    
                If link.Href.IndexOf("App_Themes/", StringComparison.InvariantCultureIgnoreCase) >= 0 AndAlso link.Href.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase) Then
                    link.Href &= "?v=" & VER_CSS
                    'link.EnableViewState = False
                End If
            End If
        Next
    

提交回复
热议问题