Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda