Skip to main content
skill CX Codex

static-import — Claude Code skill: ES2015 static imports

Walks through ES2015 import syntax and helps you decide which modules belong in the initial bundle and which should load on demand.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PatternsDev/skills --skill static-import -a claude-code
Open on GitHub

What static-import does

The skill works through a chat app: a Chat component statically imports UserProfile, ChatList and ChatInput, and ChatInput pulls in EmojiPicker the same way. Every one of those modules lands in the initial bundle, and the engine runs a module as soon as it reaches the import line.

That is where the cost shows up. In the example Webpack bundles everything into a single main.bundle.js at 1.5 MiB. The App component has to load and parse all of it before it renders anything, which hurts on a slow connection or an older device. EmojiPicker only appears after a click, so it is a candidate for a dynamic import instead.

The skill triggers on **/*.js and **/*.ts, so it applies to TypeScript projects too. Two related skills sit alongside it: module-pattern and singleton-pattern.

What it helps with

  • see which modules end up in the initial bundle
  • tell a static import from a dynamic one
  • spot a component that loads before it is needed
  • explain when an imported module actually executes
  • pick what to move to a dynamic import

Example prompts for the agent

  • list the modules in this file that go into the initial bundle
  • why does EmojiPicker load up front when it is only needed on click
  • rewrite the static ChatInput imports as dynamic ones

How to install static-import

1Skills CLI (Vercel)

npx skills add PatternsDev/skills --skill static-import -a claude-code

2Manually: put the files in place

~/.claude/skills/static-import/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/static-import/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about static-import

How do I install static-import in Claude?

Run npx skills add PatternsDev/skills --skill static-import -a claude-code. The skill file then sits at ~/.claude/skills/static-import/SKILL.md.

What does static-import do?

It teaches ES2015 static import syntax and makes clear that every statically imported module joins the initial bundle. It also points out when a dynamic import fits better.

Which files does the skill apply to?

It is scoped to **/*.js and **/*.ts, so it picks up in both JavaScript and TypeScript projects.

Source text

SKILL.md · MIT
---
name: static-import
description: Teaches static ES2015 import syntax for module dependencies. Use when you need to import code that is required at load time and benefits from static analysis and tree shaking.
paths:
  - "**/*.js"
  - "**/*.ts"
license: MIT
metadata:
  author: patterns.dev
  version: "1.1"
related_skills:
  - "module-pattern"
  - "singleton-pattern"
---

# Static Import

The `import` keyword allows us to import code that has been exported by another module. By default, all modules we're _statically importing_ get added to the initial bundle. A module that is imported by using the default ES2015 import syntax, `import module from 'module'`, is statically imported.

Let's look at an example! A simple chat app contains a `Chat` component, in which we're statically importing and rendering three components: `UserProfile`, a `ChatList`, and a `ChatInput` to type and send messages! Within the `ChatInput` module, we're statically importing an `EmojiPicker` component to be able to show the user the emoji picker when the user toggles the emoji.

## When to Use

- Use this for importing modules that are needed immediately on page load
- This is the default import mechanism — understand it to know when to switch to dynamic imports

## Instructions

- Use static imports for modules critical to the initial render
- Be aware that all statically imported modules are bundled into the initial bundle
- Consider switching to dynamic imports for modules not needed on initial render

## Details

The modules get executed as soon as the engine reaches the line on which we import them.

Since the components were statically imported, Webpack bundled the modules into the initial bundle:

```bash
Asset           Size      Chunks            Chunk Names
main.bundle.js  1.5 MiB    main  [emitted]  main
```

Our chat application's source code gets bundled into one bundle: `main.bundle.js`. A large bundle size can affect the loading time of our application significantly depending on the user's device and network connection. Before the `App` component is able to render its contents to the user's screen, it first has to load and parse all modules.

Luckily, there are many ways to speed up the loading time! We don't always have to import all modules at once: maybe there are some modules that should only get rendered based on user interaction, like the `EmojiPicker` in this case, or rendered further down the page. Instead of importing all component statically, we can _dynamically_ import the modules after the `App` component has rendered its contents and the user is able to interact with our application.

## Source

- [patterns.dev/vanilla/static-import](https://patterns.dev/vanilla/static-import)

© patterns.dev · MIT · PatternsDev/skills

Similar skills

Everything for Frontend and UI →

From the same set44

preload Guides the AI agent on preloading critical web assets. Useful when hero images, web fonts, or key bundles are discovered late in the loading waterfall. CX Codex +1 1,500installs compression A skill that walks through JavaScript compression with Gzip and Brotli so scripts move across the network faster. Useful when tuning a production build. CX Codex +1 1,500installs bundle-splitting A skill that teaches your agent to split a large JavaScript bundle into smaller ones, so the first paint comes sooner and the app becomes interactive faster. CX Codex +1 1,500installs dynamic-import Teaches coding agents on-demand module loading with dynamic import(). It helps cut initial bundle sizes by deferring non-critical components. CX Codex +1 1,500installs prpl Teaches your coding agent the PRPL pattern to speed up initial page loads and PWA performance on slow networks. CX Codex +1 1,400installs tree-shaking A skill that teaches the agent tree shaking for JavaScript bundles, so unused exports stop shipping to users. Handy when your build pulls in code nobody calls. CX Codex +1 1,400installs route-based Tells the agent how to split a single-page app by route so only the code for the current page is fetched. Useful when routes are many and the first load drags. CX Codex +1 1,400installs virtual-lists Teaches your coding agent list virtualization and windowing techniques for React. Solves scroll stutter and reduces initial rendering time for heavy datasets. CX Codex +1 1,500installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor