Pure static page, how to more elegantly strong brush

does not use any build tools, backend language
pure HTML page, how to update users automatically after each update upload

1: manually stamp?

Jan.08,2022

I have had this idea before. If you want to add a timestamp to pure html, you can only dynamically load files through javascript, for example (the following syntax is incorrect, but it is rare to think about it, just refer to it)

append('<link rel="stylesheet" href="a.css?_='+ (+new Date()) +'">')

the first thing I need to say before answering this question is the HTML page. Why is it that after each update upload, the user visits why it is not your latest upload

because the browser has a caching mechanism, the css,js and other css,js of the page will be cached automatically after the first browse

so the solutions to this problem are as follows (there should be a lot of ways, and these are the two that come to mind at present)

  1. meta refer to the original
  <META HTTP-EQUIV="pragma" CONTENT="no-cache"><!--  --> 
        <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><!--  --> 
        <META HTTP-EQUIV="expires" CONTENT="0"><!-- ; -->
  1. add a random string that follows the path of your src (or link) so that each time the submitted string changes with the new submission string, the browser will reload
if the string changes and the browser considers it to be a new file.

<script type=" text/javascript" src=" /js/test.js?+Math.random()"></script> 

it's best to use a build tool, which is more convenient, or backstage. Pure html can only load css,js dynamically, load css and js, in js and add a timeline as the logo!


< script type= "text/javascript" >

$.getScript ("test.js?v=" + Math.random (), function () {

)
$.getScript("test2.js?v="+Math.random());

});
< / script >

the method currently adopted by the subject

Menu