Say you need to include a regular ol’ script tag in a template file based on a global variable being set or not. Well, here’s a snippett you can use.

<script type="text/javascript">if (window.libName) {    const script = document.createElement('script')    script.src = "https://cdn.com/js/lib-" + window.libName +     ".min.js"    document.body.appendChild(script);}</script>

This will add a script tag with a src value that is produced by combining a value from window.libName and combining it with .min.js to create the proper path needed. After this is done, the script tag is loaded into the document using appendChild.

--

--

State machines are all the rage these days, and I think it’s for the better. I have seen several developers in the past few months or so really hammer home the idea of knowing all the states of your application before starting. They say to me, “Imagine it like this: you will know how your application will respond to anything, and everything because it will and can only respond in a way that you have determined. You are in charge of writing the state, and then writing the transitions between the states. A state will only exist if it can be safely transitioned to”. More, later.

--

--