Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Reflect changes by not having to clear cookies or refresh pages on production after upgrade

Reflect changes by not having to clear cookies or refresh pages on production after upgrade

Scheduled Pinned Locked Moved ASP.NET
javascriptcssdatabasevisual-studiosysadmin
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schatak
    wrote on last edited by
    #1

    We are getting complaints from the customer that they have to keep on refresh (Ctrl+F5) on the page or sometimes clear the cookies to reflect the changes done on upgrade. Especially, when we upload CSS/JS files or Images sometimes. To overcome this situation, I did some research and found one solution to append Query string with the name of image or CSS files. But it does not seem to be a coherent solution. Then I used NuGet packages for Bundle. It seems to be the solution but I have another issue like I am calling individual CSS file for each page (page specific) and to make a bundle for the single file is not the good idea. What should i follow as good approach to overcome this situation where changes can reflect on the server after uploading CSS/Images or JS files.

    F Richard DeemingR 2 Replies Last reply
    0
    • S Schatak

      We are getting complaints from the customer that they have to keep on refresh (Ctrl+F5) on the page or sometimes clear the cookies to reflect the changes done on upgrade. Especially, when we upload CSS/JS files or Images sometimes. To overcome this situation, I did some research and found one solution to append Query string with the name of image or CSS files. But it does not seem to be a coherent solution. Then I used NuGet packages for Bundle. It seems to be the solution but I have another issue like I am calling individual CSS file for each page (page specific) and to make a bundle for the single file is not the good idea. What should i follow as good approach to overcome this situation where changes can reflect on the server after uploading CSS/Images or JS files.

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      You've already mentioned it, a querystring variable on the css\js paths.

      S 1 Reply Last reply
      0
      • S Schatak

        We are getting complaints from the customer that they have to keep on refresh (Ctrl+F5) on the page or sometimes clear the cookies to reflect the changes done on upgrade. Especially, when we upload CSS/JS files or Images sometimes. To overcome this situation, I did some research and found one solution to append Query string with the name of image or CSS files. But it does not seem to be a coherent solution. Then I used NuGet packages for Bundle. It seems to be the solution but I have another issue like I am calling individual CSS file for each page (page specific) and to make a bundle for the single file is not the good idea. What should i follow as good approach to overcome this situation where changes can reflect on the server after uploading CSS/Images or JS files.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Mads Kristensen wrote a blog post explaining how to do this back in 2014: Cache busting in ASP.NET[^] However, I'd be inclined to use the query-string rather than a fake path. It's a fairly simple change:

        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 (string.IsNullOrWhiteSpace(rootRelativePath)) return string.Empty;

            if (rootRelativePath\[0\] != '~')
            {
                rootRelativePath = "~" + rootRelativePath;
            }
            
            string result = HttpRuntime.Cache\[rootRelativePath\] as string;
            if (result == null) 
            {
                string absolute = HostingEnvironment.MapPath(rootRelativePath);
                DateTime date = File.GetLastWriteTime(absolute); 
                result = rootRelativePath + "?v=" + date.Ticks;
                HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute)); 
            }
            
            return result; 
        } 
        

        }

        <link rel="stylesheet" href="@Fingerprint.Tag("~/content/file.css")" />


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        S 1 Reply Last reply
        0
        • F F ES Sitecore

          You've already mentioned it, a querystring variable on the css\js paths.

          S Offline
          S Offline
          Schatak
          wrote on last edited by
          #4

          Should I go with this option only?

          F 1 Reply Last reply
          0
          • S Schatak

            Should I go with this option only?

            F Offline
            F Offline
            F ES Sitecore
            wrote on last edited by
            #5

            Most people do.

            S 1 Reply Last reply
            0
            • F F ES Sitecore

              Most people do.

              S Offline
              S Offline
              Schatak
              wrote on last edited by
              #6

              Okay, I will opt the same. Thanks

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Mads Kristensen wrote a blog post explaining how to do this back in 2014: Cache busting in ASP.NET[^] However, I'd be inclined to use the query-string rather than a fake path. It's a fairly simple change:

                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 (string.IsNullOrWhiteSpace(rootRelativePath)) return string.Empty;

                    if (rootRelativePath\[0\] != '~')
                    {
                        rootRelativePath = "~" + rootRelativePath;
                    }
                    
                    string result = HttpRuntime.Cache\[rootRelativePath\] as string;
                    if (result == null) 
                    {
                        string absolute = HostingEnvironment.MapPath(rootRelativePath);
                        DateTime date = File.GetLastWriteTime(absolute); 
                        result = rootRelativePath + "?v=" + date.Ticks;
                        HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute)); 
                    }
                    
                    return result; 
                } 
                

                }

                <link rel="stylesheet" href="@Fingerprint.Tag("~/content/file.css")" />


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                S Offline
                S Offline
                Schatak
                wrote on last edited by
                #7

                Wasn't there some other setting that automatically forces updates the CSS?

                Richard DeemingR 1 Reply Last reply
                0
                • S Schatak

                  Wasn't there some other setting that automatically forces updates the CSS?

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  Only if you disable caching on the files, which will degrade the performance of your site.


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups