Chapter 16. Writing Web Applications
While JavaScript was once used to add simple interactivity to web pages, today it can be used to build complicated and fully featured software applications that run in a web browser. The possibilities include mapping, email clients, streaming video sites, real-time chat applications, and much more. The line between âwebsiteâ and âapplicationâ can be fuzzy, but one way to think about it is that an application is any site that takes user input and returns something as a result.
As a developer, you can develop these applications and deploy them instantly across the world, but this ability comes with unique challenges. As an application code base grows, you will need to split your codebase into smaller modules and ensure that users are receiving optimized code bundles. You will need to create features and experiences that compete with those of native mobile applications, such as offline functionality, notifications, and application icons. Thankfully, modern JavaScript and browser APIs enable these feature-rich experiences.
Bundling JavaScript
Problem
You want to make use of JavaScript modules in a browser environment.
Solution
Make use of native JavaScript modules or a bundling tool, such as Webpack.
Native JavaScript is supported in all modern browsers. If we have a simple module that exports a value, named mod.js
:
export
const
name
=
'Riley'
;
we can use the module natively in an HTML file:
<
script
type
=
'module'
>
import
{
name
}
from ...
Get JavaScript Cookbook, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.