Skip to the road
Adminpatchlog

Windows & PowerShell

Build Web Apps Without a Bundler: ES Modules, JSDoc and htmx

William Smith 436 travellers

Native browser modules, JSDoc checks and htmx can cut build tooling from smaller web apps. Here’s how the approach works with Vercel and Firestore.

Build Web Apps Without a Bundler: ES Modules, JSDoc and htmx

A smaller web app can often ship without the build machinery that has become standard around JavaScript projects. Native ES modules, JSDoc type checks and htmx cover several jobs commonly assigned to bundlers, TypeScript compilers and client-side frameworks. Pair them with serverless functions and a managed data store such as Firestore, and the result can be a leaner deployment path.

That approach has tradeoffs. Package resolution, dependency delivery, server-side rendering and data access still need careful design. But for applications that don’t need a large client-side framework, keeping the browser close to the platform can reduce setup and make the code easier to follow.

Let the browser load modules

Modern browsers understand ECMAScript modules, including JavaScript’s import and export syntax. A project can therefore load its own modules directly, without first combining them into a bundle. An HTML page marks its entry script with type="module", while an importmap can tell the browser where to find package names such as lodash-es.

In a typical bundled project, tools resolve package names from node_modules and prepare files for the browser. With an import map, that mapping is explicit in the page. Application code can then import local files and mapped packages in the usual way:

// app.js
import { renderUI } from './ui.js';
import { fetchUserData } from './api.js';
import { capitalize } from 'lodash-es';

document.addEventListener("DOMContentLoaded", async () => {
  const data = await fetchUserData();
  data.username = capitalize(data.username);
  renderUI(data);
});

This retains the module structure developers expect while removing a local build step. The project can avoid installing a package manager’s dependency tree for this purpose, along with the associated package.json setup.

There are reasons bundlers remain common: browsers need help resolving bare package names, many small module requests can create network delays, and production code can benefit from removing unused library code. The approach described here assigns some of that work to module CDNs. Services such as esm.sh can prepare dependencies as browser-ready ES modules, while esm.sh and Skypack can translate legacy CommonJS packages and perform tree shaking. HTTP/2 can also handle multiple requests concurrently, reducing the cost of fetching smaller files.

That convenience comes with a dependency on the CDN and its package handling. Teams should check which external packages they rely on and how those services deliver them. The practical gain is a simpler local toolchain; the tradeoff is that dependency preparation and delivery happen elsewhere.

Use JSDoc for editor type checks

TypeScript’s static checks are useful as an application grows, but a separate TypeScript compilation step isn’t the only way to get editor feedback. Many development environments use the TypeScript language server to analyze JavaScript too. Add JSDoc type annotations and the // @ts-check comment, and the editor can provide completion and flag mismatched properties while the files remain ordinary JavaScript.

// api.js
// @ts-check
/**
 * @typedef {Object} UserProfile
 * @property {string} id
 * @property {string} username
 * @property {number} reputationScore
 */

/** @returns {Promise<UserProfile>} */
export async function fetchUserData() {
  const response = await fetch('/api/user');
  return await response.json();
}

With a defined UserProfile, an editor can flag access to an undeclared field such as firstName. This gives developers a useful layer of checking without compiling TypeScript into JavaScript. The Svelte project has also moved its core codebase from TypeScript files to standard JavaScript with JSDoc annotations, citing reduced friction from the build step.

JSDoc depends on clear annotations and editor support, so it won’t remove the need for deliberate type design. It does offer a middle path for teams that want checks and completion but prefer to run JavaScript directly.

Let the server own page state

Client-side frameworks often keep a copy of application state in the browser and coordinate it with server and database state. For simpler interactions, htmx offers another model: HTML attributes can trigger requests and insert returned HTML into the page. The server remains responsible for the current data and the markup that represents it.

For example, a button can make a GET request to a serverless endpoint and swap the response into a #profile-card element. The response can include the updated profile markup, which htmx places in the DOM. This avoids a separate client-side step to parse JSON, map its fields and build the corresponding interface.

htmx also provides declarative ways to handle interactions such as loading indicators and errors. For the particular request and update described here, the page can require no custom JavaScript. More complex client-side behavior may still call for JavaScript or a framework; the appeal is that ordinary server-rendered interactions don’t automatically need them.

Connect Firestore to serverless functions

The example architecture uses Firestore as a managed document store and Vercel serverless functions to handle requests. Firestore has been available since 2017. Its document model lets an application retrieve a record without setting up SQL migrations, managing database connection pools or operating a dedicated database instance as part of this design.

A serverless function can use the Firebase Admin SDK to read a Firestore document, then return HTML for htmx to insert. In the example, the function reads the users/matt_t document, returns a not-found response when it doesn’t exist, and otherwise builds a profile fragment containing the username and reputation score. It sets the response content type to text/html; the example also returns an error response if the database operation fails.

Credentials in the example come from the FIREBASE_CREDENTIALS environment variable. That detail matters in deployment: the function needs the right credentials and access to the intended Firestore project. The compact handler combines routing, data retrieval and markup generation, but teams still need to decide how to handle authentication, input validation and more elaborate page rendering.

Choose the lighter path where it fits

This setup combines browser-native modules, editor-based checks, server-rendered HTML and managed infrastructure. Its strongest case is an application whose interactions can be handled through requests and HTML fragments, without maintaining extensive client-side state.

Before adopting it, check whether the app depends on packages that require bundler-specific transforms, whether its dependency CDN is suitable for the deployment, and whether server-rendered updates meet the interface requirements. For the right project, the result is a shorter local toolchain and fewer moving parts between editing JavaScript and deploying it.

Source: William Smith · www.infoworld.com

On the same route