Yesterday, I posted about the Code Snippets feature inside the Chrome Developer tools. One thing that is annoying is that you have to create your scripts locally and there is no built-in way to share them.
Gleb Bahmutov brought a solution by sharing a code snippet to load your scripts dynamically. A good idea is to set up an internal site where you host all the snippets you want to share. These scripts can then be loaded using the following script:
This file contains 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
(function downloadAndRunCodeSnippet() { | |
var url = 'http://internaldevserver/codesnippets/sample.js'; | |
var head = document.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = url; | |
head.appendChild(script); | |
}()); |
Note: By using this script it is possible to load snippets from any source. Be careful as this imposes a security risk if you load and execute scripts from other locations.