This HTML template provides a complete single-page application with modern JavaScript functionality, integrated logging, and responsive design. All JavaScript logic is centralized in main.js for maintainability and clean separation of concerns.
- Open
client/pages/index.htmlin a web browser - Or serve via local server:
python -m http.server 8000 - Navigate to:
http://localhost:8000/client/pages/index.html
Javascript-template/
βββ main.js # Main application logic
βββ client/
β βββ pages/
β β βββ index.html # HTML template
β βββ css/
β βββ base.css # Styling
βββ server/
βββ scripts/
βββ simple-logger.js # Logging utility
- Light/Dark Mode Toggle: Click π/βοΈ buttons in header or settings modal
- Persistent Theme: Maintains theme state during session
- Smooth Transitions: CSS-based theme switching with animations
- Dual Controls: Theme toggle available in both header and settings modal
// Theme is controlled via data-theme attribute
document.documentElement.setAttribute("data-theme", currentTheme);- Tab-Based Navigation: Home, About, Projects, Contact pages
- Active State Management: Visual indication of current page
- Smooth Page Transitions: Content switching without page reload
- URL Fragment Support: Smooth scrolling to anchor sections
// Navigation handled via data-page attributes
const pageId = button.getAttribute("data-page");
showPage(pageId);- Settings Modal: Configurable application settings
- Outside Click Dismiss: Click outside modal to close
- ESC Key Support: Close with escape key
- Theme Controls: Duplicate theme toggle in modal
- Log Level Configuration: Runtime logging level adjustment
- Visual Progress Feedback: Animated progress bar in footer
- Smooth Animation: 50-step progression with realistic variations
- Auto-Reset: Automatically resets after completion
- Logging Integration: Progress events logged with timestamps
// Progress simulation with realistic animation
const totalSteps = 50;
const variation = (Math.random() - 0.5) * 1; // Β±0.5% variation- 5-Level Logging: ERROR, WARN, INFO, DEBUG, DEV
- Browser Console Output: Formatted, colored log messages
- Structured Data: JSON-formatted log context
- Runtime Level Control: Adjust logging verbosity via settings
- Timestamp Precision: Millisecond-accurate timestamps
Log Levels:
NONE: No loggingLOW: Errors onlyMED: Errors + WarningsHIGH: Errors + Warnings + Info + Debug (default)DEV: Everything including development messages
// Logger initialization
const logger = new SimpleLogger({
appName: "HTMLTemplate",
level: "HIGH",
compactMode: true,
showProcessId: false,
enableFileLogging: false
});- Window Resize Detection: Debounced resize event logging
- Smooth Scrolling: Enhanced anchor link behavior
- Click Event Management: Proper event delegation
- Keyboard Support: Modal ESC key handling
- Test Logging: Demonstrates all log levels with sample data
- Progress Simulation: Shows realistic progress bar animation
- Theme Testing: Instant theme switching validation
- Navigation Testing: Page switching functionality
- Modular Design: Separated concerns with clear function boundaries
- Event-Driven: Uses event listeners for all user interactions
- State Management: Simple state tracking for theme and navigation
- Error Handling: Graceful degradation for missing elements
- Debounced Events: Window resize events debounced to 250ms
- Efficient Animations: RequestAnimationFrame-style progress updates
- Memory Management: Proper interval cleanup and event removal
- Lazy Loading: Events attached after DOM ready
- Modern JavaScript: ES6+ features (arrow functions, const/let)
- DOM APIs: Uses standard DOM manipulation methods
- CSS Integration: Leverages CSS custom properties for theming
- Console Integration: Works with all major browser dev tools
- Create page content div with
page-contentclass - Add navigation button with
data-pageattribute - Update
showPage()function if needed
<div id="newPage" class="page-content" style="display: none">
<h1>New Page</h1>
<!-- Page content -->
</div>// Change default logging level
logger.setLevel('DEV'); // Shows everything
// Add custom log messages
logger.info("Custom event", { userId: 123, action: "custom" });Modify CSS custom properties in base.css:
:root {
--primary-color: #your-color;
--background: #your-background;
}// Follow the existing pattern
const newButton = document.getElementById("newButton");
newButton.addEventListener("click", () => {
logger.info("New button clicked");
// Your functionality here
});- Theme toggle works (header and modal)
- All navigation tabs switch content
- Settings modal opens/closes
- Progress bar animation completes
- Log messages appear in console
- Smooth scrolling to anchors works
- Window resize events logged
Test features directly in browser console:
// Test logging
testLogging();
// Test progress
simulateProgress();
// Change theme programmatically
toggleTheme();
// Check current log level
logger.getLevel();- Lightweight: ~15KB total JavaScript (including logger)
- Fast Load: No external dependencies
- Responsive: Smooth 60fps animations
- Memory Efficient: Proper cleanup of intervals and timeouts
- Check Console: All interactions are logged
- Network Tab: Verify all files load (no 404s)
- Elements Tab: Inspect theme attribute changes
- Sources Tab: Set breakpoints in main.js for debugging
- Minification: Consider minifying main.js for production
- CDN: Host static assets on CDN if needed
- Caching: Implement proper cache headers
- Error Tracking: Add error boundary handling
- Analytics: Integrate usage tracking if required
- Required:
simple-logger.js(logging functionality) - Required:
base.css(styling and theme variables) - Optional: Favicon for complete branding
This template provides a solid foundation for building modern web applications with proper logging, theming, and user interaction patterns.