Skip to content

Instantly share code, notes, and snippets.

@nwrox
Created May 11, 2017 18:58
Show Gist options
  • Save nwrox/de4fd4b538c6c8290a4df705d91eb5a9 to your computer and use it in GitHub Desktop.
Save nwrox/de4fd4b538c6c8290a4df705d91eb5a9 to your computer and use it in GitHub Desktop.
const createScript = (path, version) => {
const scriptTag = document.createElement('script')
scriptTag.src = path + '?v=' + version
scriptTag.type = 'text/javascript'
document.head.appendChild(scriptTag)
}
const createStyle = (path, version) => {
const linkTag = document.createElement('link')
linkTag.href = path + '?v=' + version
linkTag.rel = 'Stylesheet'
linkTag.type = 'text/css'
document.head.appendChild(linkTag)
}
const getCurrentTimeMillis = () => new Date().getTime()
const invalidResource = () => { throw Error('Recurso inválido.') }
const randomizeResources = (arrResources) => {
for(let res of arrResources)
(res.endsWith('.js')) ? createScript(res, getCurrentTimeMillis())
: (res.endsWith('.css')) ? createStyle(res, getCurrentTimeMillis())
: invalidResource()
}
// execução
const resources = [ /* Seus recursos aqui (css/js) */ ]
randomizeResources(resources);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment