Created
May 11, 2017 18:58
-
-
Save nwrox/de4fd4b538c6c8290a4df705d91eb5a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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