【AI開発】単一HTMLファイルを分割してトークン消費量を節約する方法【プロンプト・実装例あり】 #Python - Qiita
@uni928

【AI Development】How to Split a Single HTML File to Save on Token Consumption【Includes a Prompt and Implementation Example】

  • AI
  • HTML
  • JavaScript
  • Python
  • Generative AI
TAG26
TAG280
TAG33@@
Last updated at 2026-11-11Posted at 2026-11-11
TAG40@@
As you continue modifying a single HTML file using AI tools such as ChatGPT and Codex, token consumption becomes a concern as the file grows.

So, I tried splitting a single HTML file into multiple files for management and modifying only the parts that are needed.

How It Works

The basic workflow is as follows:

  1. Split a single HTML file into HTML, CSS, JavaScript, and so on
  2. Have the AI load the files needed for the modifications, focusing on those files
  3. After making the modifications, combine the split files using Python
  4. Ultimately, use the result as a single HTML file, as before

The advantage of splitting is that it reduces the need to have the AI load the entire, huge HTML file every time.

Also, because the combining process is performed on the Python side, there is no need to have the AI output the entire completed HTML file.

Key Points for Saving Tokens

For example, when modifying a 100KB single HTML file, you would previously often have to load the entire file.

However, if you split it by feature, you may be able to focus the modifications on just a few KB of JavaScript.

This can potentially reduce both input and output tokens.

However, depending on the AI development environment and the nature of the work, you may also need to load related files or the overall structure, so token consumption is not necessarily reduced.

Publishing the Splitting Prompt

This time, I bundled the prompt and sample files for splitting and managing a single HTML file into a ZIP.

The ZIP also includes the implementation example as a ZIP, along with a Python script for recombining the files into a single HTML file.

This seems useful when you want to continue publishing and distributing the project as a single HTML file while minimizing the tokens consumed by ongoing AI-based modifications.

In particular, if you keep adding features to a single HTML file, I think it is worth trying.

※The effectiveness of token reduction varies depending on the development details and the AI usage environment.

Prompt (Must attach three items, including ZIP files)
Because of the token limit, please split the attached single HTML file into smaller pieces. Please split the attached single HTML file into smaller pieces and place them in the attached empty folder. The attached ZIP file (HTML splitting method sample.zip) is an example of the splitting method. Split the HTML file currently being developed into smaller pieces and place them in the attached folder to reduce the number of tokens used in Codex development. Also, create a file for combining them into a single file.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
Sign upLogin