Due to the limited ressources of our IoT-devices we should try to optimize our code, in case we do not want to wait long time each time we access our nodes. In this post I will present you some simple tricks how you can make your device more reactive. The actions are listed from very quick steps to a bit more complex tasks. (May I am going to update this post after some time.)

  1. Enable browser-caching

  2. Load frameworks via CDNs, if possible

    The next step is to reduce the amount of code which comes from your IoT-device. Most frameworks are also hosted via content distribution networks. This means that you do not need to serve the files directly from your device. But be aware: If you want to use your node as a standalone device your site will not be shown in the correct way, because this files will/can not be downloaded to your client!

  3. Minify your code

    You may have noticed that unnecessary blanks or line breaks also cost space. So it is a good practice to remove them, respectively minify your code. This can be done with some task runners or some code editors. When I am developing for my nodes I usally prefer the way via a good code editor. Therefore I use Visual Studio Code and the extension minify.

  4. Review your UI-code if you need all the functionality

    Sometimes we developers tend to implement functions which are nice to have or functions which we wanted to program because we wanted to master a challenge. Quite often these functions will not add a benefit to your project. So why keep them in your productive code? ==> Keep them in your GIT-repository so that you can get it whenever you really need it.

  5. Get support from frameworks

    Check if it is possible to write your code in a more efficient way. You may have a look at frameworks like underscore or Lodash. These frameworks can reduce your code size, especially when you are working with arrays and objects, because they provide a lot of common functions. This makes sense if your node is not isolated (so you can use CDNs)! Otherwise it could be better if you stick to your own functions.

Previous Post Next Post