One-click localization of HTML external resources for truly offline pages
English | 简体中文
HTML Assets Localizer is a powerful resource localization tool that automatically downloads all external JavaScript and CSS resources referenced in HTML files and rewrites the reference paths. Whether you're creating offline demos, archiving web pages, or working in network-restricted environments, it's your best choice.
| Feature | Description |
|---|---|
| 🚀 Fast Localization | Automatically identify and download all external JS/CSS resources |
| 🎯 Smart Path Rewriting | Automatically update resource reference paths in HTML |
| 💻 Dual Experience | Provides both CLI command-line and visual UI modes |
| 📦 Ready to Use | Supports global installation or integration as an npm package |
| 🔧 Flexible Configuration | Supports custom output directories and file organization |
| 🛡️ Safe & Reliable | Automatically handles filename conflicts to avoid resource overwrites |
# Clone the repository
git clone https://github.com/YangsonHung/html-assets-localizer.git
cd html-assets-localizer
# Install dependencies
pnpm install
# Compile TypeScript
pnpm run build💡 Tip: Unless you modify the source code, you typically only need to compile once.
⚠️ Requires Node.js 20.19+ (or the latest 22.x LTS) because the build pipeline is powered by Vite 7.
# Using pnpm
pnpm add -g html-assets-localizer
# Using npm
npm install -g html-assets-localizer
# Using yarn
yarn global add html-assets-localizerAfter global installation, you can use html-assets-localizer or the shorthand hal from any directory.
Perfect for quick processing and automation scenarios.
# Full command
html-assets-localizer <html-file> <output-dir>
# Shorthand command
hal <html-file> <output-dir># Process a single HTML file
hal index.html ./offline-bundle
# Run from source
node dist/cli.js example.html ./outputExecution Results:
- ✅ Creates
js/andcss/subdirectories under<output-dir> - ✅ Downloads all external resources to corresponding directories
- ✅ Generates a new HTML file with paths updated to local references
- ✅ Prints resource mapping details in the terminal
| Command | Description |
|---|---|
hal help |
📖 Display help information |
hal version |
🔖 Show current version |
hal ui |
🖥️ Launch visual interface |
Ideal for team collaboration and users unfamiliar with command-line tools.
# Default startup (auto-select port and open browser)
html-assets-localizer ui
# Or use shorthand
hal ui# Specify port and host address
hal ui --port 4173 --host 0.0.0.0
# Start without auto-opening browser
hal ui --no-open- 📤 Drag & Drop HTML file upload
- 📊 Real-time View download progress and logs
- 📥 One-click Download processed offline package
- 🎨 Friendly Interface no command-line knowledge required
Integrate the tool into your Node.js projects.
npm install html-assets-localizerimport { HtmlAssetsLocalizer } from 'html-assets-localizer';
// Create instance
const localizer = new HtmlAssetsLocalizer({
htmlFilePath: './example.html',
targetDir: './offline',
});
// Execute processing
const summary = await localizer.process();
// View results
console.log('Processing complete!');
console.log('Asset list:', summary.assets);
console.log('Output path:', summary.outputPath);// Batch process multiple files
const files = ['page1.html', 'page2.html', 'page3.html'];
for (const file of files) {
const localizer = new HtmlAssetsLocalizer({
htmlFilePath: file,
targetDir: `./output/${file.replace('.html', '')}`,
});
await localizer.process();
console.log(`✅ ${file} processed successfully`);
}Use the library directly in browsers (including GitHub Pages) without any backend.
<!-- Always pulls the latest published bundle -->
<script src="https://unpkg.com/html-assets-localizer/dist/index.umd.js"></script>
<script>
const { BrowserHtmlAssetsLocalizer } = window.HtmlAssetsLocalizer;
async function localizeFile(file) {
const htmlContent = await file.text();
const localizer = new BrowserHtmlAssetsLocalizer({
htmlContent,
htmlFileName: file.name,
});
const result = await localizer.process();
// Trigger download
const url = URL.createObjectURL(result.zipBlob);
const link = document.createElement('a');
link.href = url;
link.download = result.zipFileName;
link.click();
URL.revokeObjectURL(url);
}
</script>
⚠️ Note: the browser mode still follows standard CORS restrictions—resources blocked by the remote server cannot be fetched.
File organization after processing:
output-dir/
├── index.html # HTML file with updated paths
├── js/ # JavaScript resources directory
│ ├── jquery.min.js
│ ├── bootstrap.min.js
│ └── app.js
└── css/ # CSS resources directory
├── bootstrap.min.css
├── style.css
└── theme.css
- ✅ Maintain a stable network connection to avoid download interruptions
- ✅ For large projects, test with a single file first
- ✅ Using CDN acceleration may affect download speed
- Filename Conflicts: The tool automatically adds numeric suffixes (e.g.,
style.css,style-1.css) - Download Timeout: Check network connection and retry later
- Invalid Resources: Ensure external URLs in the original HTML are valid
- Version Control: Recommend including generated offline packages in version control
- Regular Updates: Periodically re-localize to get resource updates
- Testing: Test page functionality in local environment after generation
- Backup Originals: The tool generates new files, but keep original HTML as backup
If you need to modify tool functionality:
# 1. Edit source files in src/ directory
vim src/localizer.ts
# 2. Recompile
pnpm run build
# 3. Test modifications
node dist/cli.js test.html outputhtml-assets-localizer/
├── src/ # TypeScript source
│ ├── cli.ts # CLI entry point
│ ├── index.ts # Package exports
│ ├── localizer.ts # Core localization pipeline
│ ├── types.ts # Shared type declarations
│ ├── browser/ # Browser bundle entry (UMD)
│ │ ├── index.ts
│ │ └── localizer.ts
│ └── server/
│ └── uiServer.ts # Express-powered UI launcher
├── tests/
│ └── localizer.test.ts # Vitest coverage for HTML flows
├── docs/ # UI documentation and static assets
├── archive/ # Archived examples and legacy assets
├── example.html # Ready-to-run sample HTML file
├── .github/ # GitHub workflows and issue templates
├── AGENTS.md # Contributor quick-start guide
├── CHANGELOG.md # Release notes
├── CONTRIBUTING.md # Detailed contribution process
├── package.json # Project metadata and scripts
├── pnpm-lock.yaml # Locked dependency graph
├── tsconfig.json # TypeScript compiler options
├── vite.config.ts # CLI build configuration
├── vite.browser.config.ts # Browser bundle configuration
├── vitest.config.ts # Vitest runner setup
├── README.md / README.zh.md # Documentation (English & Chinese)
└── dist/ (generated) # Build output produced by `pnpm run build`
Issues and Pull Requests are welcome! Please read CONTRIBUTING.md for development workflow, coding conventions, and submission guidelines.
This project is licensed under the MIT License.
- 📦 NPM Package
- 💻 GitHub Repository
- 📖 中文文档
Made with ❤️ by YangsonHung
If this project helps you, please give it a ⭐ Star!