Loading script from an external site

The developer framework is great for building quick and simple modifications using javascript, but it can also be used to build out complex additional functions interacting with multiple parts of the page, or multiple systems to do some pretty impressive things.

If you've ever developed some serious functionality in javascript you will know that, due to the flexibility it affords, it can quickly spider out of control and become difficult to manage. This can be made even worse if there are multiple developers working on the system since there is only one place in the system to enter code.

A simple, but very powerful solution to this problem is to host javascript files on another website, such as a CDN, or your organisations own public facing website and add these to your intranet pages using developer framework.

The code sample below shows how to append a single file to the head of the page, but using an array or something similar this would be very easy to incorporate multiple files.

  var script   = document.createElement("script");
  script.type  = "text/javascript";
  script.src   = "https://my.web.com/codefile.js";    // use this for linked script

Other advantages this approach gives you are

  • Modular files - Using this approach you can modularise your code, meaning that all code that implements a specific feature can be contained within a single code file.
  • Developer separation - If all your developers have their own source files then this mitigates the risk of one developer overwriting some changes another developer has made
  • Source control - Since the files are hosted as physical files in another website, rather than saved to the interact file system, you can easily include this code in your source control system
  • Deploying between environments - The standard approach to copying code changes between environments such as sandbox and live is to copy and paste between them. Copy and paste is prone to human error, but using this approach means you simply load the file in the second environment for instant deployment
  • Error correction - A simple error in javascript, such as a misplaced bracket can stop all the javascript from working on your site, and effectively break Interact. Undoing that change can be tricky if the developer framework is not accessible, so having the code hosted outside of Interact can make it easier to remove the problem code and bring Interact back to life.