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

191
Vistas
How to make script execute once the first script is loaded

I'm trying to make a web framework and one feature will be a key-value state management tool. I need the second <script> tag to only run after ./script.js loads in.
index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./framework.js"></script>
</head>
<body>
  <p f-text="name"></p>
  <script>
    Framework.store('name', 'Joe');
  </script>
</body>
</html>

framework.js:

document.querySelectorAll('*').forEach((element) => {
  if (element.hasAttribute('f-text')) {
    const textValue = element.getAttribute('f-text');

    const key = window.fStore.find((x) => x.key === textValue);

    element.innerHTML = key.value;
  }
});

window.Framework = {
  store: (key, value?) => {
    if (!value) {
      const foundKey = window.fStore.find((x) => x.key === key);

      return foundKey.value;
    }

    window.fStore = [...window.fStore, { key: key, value: value }];
  }
}

Error:

SyntaxError: Unexpected token ')'
    at /framework.js:12:22
ReferenceError: Framework is not defined
    at /:12:5
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to wait that your script is loaded, you can use this

window.addEventListener('load', function() {
    Framework.store('name', 'Joe');
})
about 4 years ago · Juan Pablo Isaza Denunciar
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