Force Hard Reload












1














I am currently attempting to create a simple test to test the speed of the client's PC by rendering an image. The issue is on browsers such as Safari and Chrome images a saved in some way to allow for a quick reload speed. For example when using the following code



var speed = document.getElementById('speed');
var startTime = new Date().getTime();
var img = new Image();
img.onload = function() {
var stopTime = new Date().getTime();
var loadtime = Math.round((stopTime - startTime) / 100);
}
img.src = "testImage.jpg";


The variable loadtime is 8 at first and then 0 after a refresh. My guess is Safari saves the image to load it instantly. On Chrome it's the same issue unless I do a hard reload. I've tried putting these meta tags but with no luck.



<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />


I've also tried



location.reload(true);


As suggested here but it doesn't seem to do the trick.



Is it possible to force a hard reload without the client's consent or chose? Or is it some sort of security infringement?










share|improve this question



























    1














    I am currently attempting to create a simple test to test the speed of the client's PC by rendering an image. The issue is on browsers such as Safari and Chrome images a saved in some way to allow for a quick reload speed. For example when using the following code



    var speed = document.getElementById('speed');
    var startTime = new Date().getTime();
    var img = new Image();
    img.onload = function() {
    var stopTime = new Date().getTime();
    var loadtime = Math.round((stopTime - startTime) / 100);
    }
    img.src = "testImage.jpg";


    The variable loadtime is 8 at first and then 0 after a refresh. My guess is Safari saves the image to load it instantly. On Chrome it's the same issue unless I do a hard reload. I've tried putting these meta tags but with no luck.



    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="-1" />


    I've also tried



    location.reload(true);


    As suggested here but it doesn't seem to do the trick.



    Is it possible to force a hard reload without the client's consent or chose? Or is it some sort of security infringement?










    share|improve this question

























      1












      1








      1







      I am currently attempting to create a simple test to test the speed of the client's PC by rendering an image. The issue is on browsers such as Safari and Chrome images a saved in some way to allow for a quick reload speed. For example when using the following code



      var speed = document.getElementById('speed');
      var startTime = new Date().getTime();
      var img = new Image();
      img.onload = function() {
      var stopTime = new Date().getTime();
      var loadtime = Math.round((stopTime - startTime) / 100);
      }
      img.src = "testImage.jpg";


      The variable loadtime is 8 at first and then 0 after a refresh. My guess is Safari saves the image to load it instantly. On Chrome it's the same issue unless I do a hard reload. I've tried putting these meta tags but with no luck.



      <meta http-equiv="cache-control" content="no-cache" />
      <meta http-equiv="Pragma" content="no-cache" />
      <meta http-equiv="Expires" content="-1" />


      I've also tried



      location.reload(true);


      As suggested here but it doesn't seem to do the trick.



      Is it possible to force a hard reload without the client's consent or chose? Or is it some sort of security infringement?










      share|improve this question













      I am currently attempting to create a simple test to test the speed of the client's PC by rendering an image. The issue is on browsers such as Safari and Chrome images a saved in some way to allow for a quick reload speed. For example when using the following code



      var speed = document.getElementById('speed');
      var startTime = new Date().getTime();
      var img = new Image();
      img.onload = function() {
      var stopTime = new Date().getTime();
      var loadtime = Math.round((stopTime - startTime) / 100);
      }
      img.src = "testImage.jpg";


      The variable loadtime is 8 at first and then 0 after a refresh. My guess is Safari saves the image to load it instantly. On Chrome it's the same issue unless I do a hard reload. I've tried putting these meta tags but with no luck.



      <meta http-equiv="cache-control" content="no-cache" />
      <meta http-equiv="Pragma" content="no-cache" />
      <meta http-equiv="Expires" content="-1" />


      I've also tried



      location.reload(true);


      As suggested here but it doesn't seem to do the trick.



      Is it possible to force a hard reload without the client's consent or chose? Or is it some sort of security infringement?







      javascript html reload






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 0:58









      Jack Stoller

      468110




      468110
























          2 Answers
          2






          active

          oldest

          votes


















          3














          Setting meta tags and reloading the HTML page does not affect the caching of the image. If you want to avoid caching the image try appending a random query parameter each time for example.



          img.src = "testImage.jpg?q=" + Math.random().toString(16).slice(2);





          share|improve this answer





























            2














            You could add a harmless query parameter to the end of the url to break the browser's caching:



            img.src="testImage.jpg?noop=<incrementing_number_here>"





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291673%2fforce-hard-reload%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Setting meta tags and reloading the HTML page does not affect the caching of the image. If you want to avoid caching the image try appending a random query parameter each time for example.



              img.src = "testImage.jpg?q=" + Math.random().toString(16).slice(2);





              share|improve this answer


























                3














                Setting meta tags and reloading the HTML page does not affect the caching of the image. If you want to avoid caching the image try appending a random query parameter each time for example.



                img.src = "testImage.jpg?q=" + Math.random().toString(16).slice(2);





                share|improve this answer
























                  3












                  3








                  3






                  Setting meta tags and reloading the HTML page does not affect the caching of the image. If you want to avoid caching the image try appending a random query parameter each time for example.



                  img.src = "testImage.jpg?q=" + Math.random().toString(16).slice(2);





                  share|improve this answer












                  Setting meta tags and reloading the HTML page does not affect the caching of the image. If you want to avoid caching the image try appending a random query parameter each time for example.



                  img.src = "testImage.jpg?q=" + Math.random().toString(16).slice(2);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 1:01









                  AJcodez

                  14.5k95797




                  14.5k95797

























                      2














                      You could add a harmless query parameter to the end of the url to break the browser's caching:



                      img.src="testImage.jpg?noop=<incrementing_number_here>"





                      share|improve this answer


























                        2














                        You could add a harmless query parameter to the end of the url to break the browser's caching:



                        img.src="testImage.jpg?noop=<incrementing_number_here>"





                        share|improve this answer
























                          2












                          2








                          2






                          You could add a harmless query parameter to the end of the url to break the browser's caching:



                          img.src="testImage.jpg?noop=<incrementing_number_here>"





                          share|improve this answer












                          You could add a harmless query parameter to the end of the url to break the browser's caching:



                          img.src="testImage.jpg?noop=<incrementing_number_here>"






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 1:01









                          Danny Delott

                          3,38111537




                          3,38111537






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291673%2fforce-hard-reload%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Guess what letter conforming each word

                              Port of Spain

                              Run scheduled task as local user group (not BUILTIN)