Do you already know the RequireJS? link
RequireJS is a loader of JavaScript files and modules. It's a javascript library.
Download at link
or refer to your html on the CDN //cdnjs.cloudflare.com/ajax/libs /require.js/2.1.14/require.min.js
With RequireJS you are informed that some of your javascript code requires, ie you need another javascript library to be loaded.
Example (adapting from link ):
Let's say your site has this structure:
project-directory/
--project.html
--scripts/
----cadastro.js
----exibirMensagem.js
----require.min.js (faça o download em http://requirejs.org/docs/release/2.1.14/minified/require.js )
Then in your HTML do something like:
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<!-- O atributo data-main diz para o require.js carregar
scripts/cadastro.js depois que o require.js seja carregado. -->
<script data-main="scripts/cadastro" src="scripts/require.js"></script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
Finally inside your cadastro.js you do something like:
require(["exibirMensagem"], function(exibirMensagem) {
if (nome == ""){ exibirModal(); }
//Essa função será executada quando exibirMensagem.js for carregado.
//Se exibirMensagem.js usar o método define() (mais detalhes em http://requirejs.org/docs/api.html#define ), então essa função só será disparada quando todos os módulos definidos forem carregados.
});
I hope it helps.