/
3.5 - Hosting External Javascript

3.5 - Hosting External Javascript


Overview:

As mentioned above, it’s good practice to host your Javascript files separate to your HTML code.

There are three main ways to host external Javascript:


In an Interaction:

It is possible to create a message interaction, and use it for Javascript code. Simply create a message interaction in the same way you did in the previous lesson.


Tip: Name your interaction with a “.js” extension as an easy way to find your Javascript interactions. Eg. mycode.js


The URL you will use in your “External Javascript” box on the “answerSpace Setup” page will be similar to:


//blinkm.co/_api/interaction/run/ANSWERSPACE/INTERACTION


So if your answerSpace name is “myanswerspace”, and your Javascript interaction is “mycode.js”, then your full URL would be:


//blinkm.co/_api/interaction/run/myanswerspace/mycode.js


In the Asset Manager:

The Asset Manager can be used to host static files. This is most commonly used for images, however it can also be used for Javascript files too.


Note: Keep in mind that the Asset Manager uses AWS Cloudfront, which will create copies of your files close to points in the world where users access your app. This means any updates to the files can take up to twenty minutes to take effect. For this reason, we recommend you only use the Asset Manager for files that don’t change often, or if you do need to replace a file, change the filename by adding a version number to it.


To upload your Javascript files to the Asset Manager, go to the “Manage” menu and select “Assets”.

You can upload the your Javascript file, and once the list refreshes you will see your file listed there. Right-click on the icon and copy the link. It should look something like:
 

//d2g691qpj752hh.cloudfront.net/company/answerspace/mycode.js


Paste this into the “External Javascript” box on the “answerSpace Setup” page.


Web Client Hosting:

While you’re currently using the CMS environment to create your answerSpace, keep in mind the full range of the Blink Mobility Platform is available to you, and you’re able to use any of the services you need.

Web Client Hosting is a service that allows you to host static files in our CDN, and is accessible via the Web Client Deploy CLI. This is a more advanced method of managing your External Javascript files, and will also give you the ability to manage your Javascript files locally, and even store them in a code repo like the BlinkMobile Hosted Gitlab (a fully hosted private repo for BlinkMobile partners and developers).


Note: For more information about Web Client Hosting, you can read the developer documentation here


The Client CDN will give you a URL similar to:

//company-project-environment.blinkm.io/mycode.js


You can copy and paste this URL into the “External Javascript” box on the “answerSpace Setup” page.


Next: