0

JS example:

<script src="{{ url_for('static', filename='scripts/openchat.js') }}"></script>

I've noticed that when i inspect source in web browser i see some of website like this myscript.js?er2dfsdsfsdf44455230099 my file structure

enter image description here

i did lots of google, but i can't found any proper answer. can anyone help on this.

Ankit Singh
  • 327
  • 4
  • 12

3 Answers3

0

I think creating the scripts tag dynamically could help you. Please try this

<script>
  document.addEventListener("DOMContentLoaded", () => {
    const filenames = ["myscript.js", "myotherscript.js"];
    const body = document.body;

    for (const filename of filenames) {
      const script = document.createElement("script");

      script.src = `${filename}?${Date.now()}`;
      script.type = "javascript";

      body.appendChild(script);
    }
  });
</script>
Mario
  • 4,784
  • 3
  • 34
  • 50
  • i try your code it not showing anything in console and not loading – Ankit Singh Jun 24 '20 at 21:36
  • For this script to go into the context of your question you need to test it in an html document. How have you tried it? – Mario Jun 24 '20 at 23:19
  • Are you sure this code works because is not showing anything – Ankit Singh Jun 25 '20 at 04:04
  • it should not show anything, inspect the dom, it should have added just before closing the body tag a script tag for each script in the filenames array plus the timestamp that would make your script have a different src every time you visit the page – Mario Jun 25 '20 at 04:15
  • I added there only but it not taking JS files into the load – Ankit Singh Jun 25 '20 at 04:16
  • It is only an example, it should not load anything, it just shows how you can add a number in this case the timestamp to the file name, the way I propose is to create the script tags programmatically, this way I think you will avoid the problem you describe in your question – Mario Jun 25 '20 at 04:21
0

I think maybe you just need to hard reload your web browser. Search on the internet how to hard reload you're web browser. Because I don't know your browser I can't tell you right now.

aparep7474
  • 79
  • 7
0

because of i am using flask url_for method to call JS files, so i found a manual solution for adding version in my JS or CSS files. I found this

<script src="{{ url_for('static', filename='scripts/openchat.js' , v='14') }}"></script>

but i want to find automate method for this thank you for support.

Ankit Singh
  • 327
  • 4
  • 12