Implement Inline JavaScript


Part One Chapter 12

JavaScript

When your mobile web pages require using large JavaScript block of codes for user interaction or user data tracking, the best practice is to include your JavaScript in an external file (or several external files). This JavaScript setup will maximize your mobile web pages' load speed.

In other cases when your mobile web pages only have to use very few lines of JavaScript codes, it may not make sense to include your JavaScript codes in external files. It is better to place your JavaScript codes “inline” – Within your mobile web pages' HTML codes. This setup will reduce the number of http requests to external JavaScript files and allow your pages to load faster.

Add JavaScript to Web Pages

When adding inline JavaScript onto your mobile web pages, it must be inserted between the “script” tags. For example:

<script>
  // Your JavaScript Codes
</script>

One disadvantage with this setup is that web browsers will not cache the inline JavaScript as external JavaScript files.



Gordon Choi's Mobile Website Book has been available since November 2016.







Content on Gordon Choi's Mobile Website Book is licensed under the CC Attribution-Noncommercial 4.0 International license.

Gordon Choi's Mobile Website Book

Gordon Choi’s Other Websites:
SEO Expert in Hong Kong (Gordon Choi’s Blog)
Analytics Book