Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How to refresh client cache automatically when importing JS in JS?

this is "modules.js" file before change

class myClass {
  constructor() {
    // do nothing
  }

  foo() {
    alert("foo");
  }
}

and this is "script.js" file before change.

import {
  myClass
} from "modules.js";

const myInstance = new myClass();

myInstance.foo();

I have changed these files to like below:

modules.js

class myClass {
  constructor() {
    // do nothing
  }

  foo() {
    alert("foo");
  }

  bar() {
    alert("bar");
  }
}

script.js

import {
  myClass
} from "modules.js";

const myInstance = new myClass();

myInstance.foo();

myInstance.bar();

an then I uploaded these files to my server and accessed the page.
the <script> tag which calls "script.js" is written like this:

<script type="module" src="script.js?ver=<?php echo date('Y-m-dH:i:s'); ?>"></script>

and the page throwed an error like "myInstance.bar is not defined"
I guess the problem is this. cache of "script.js" has been refreshed by

?ver=<?php echo date('Y-m-dH:i:s'); ?>

this code, but "modules.js" didn't.
so I want to refresh client cache of a JS file which is imported in js, not used as source of <script> tag.
can you suggest me any way to refresh the cache(or file)?
thank you for reading my question.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!