Overview
Themain.js file is the primary entry point for all JavaScript functionality in the FreshJuice DEV theme. It initializes Alpine.js, registers plugins, loads utilities, and sets up the application when the DOM is ready.
Location
Dependencies
The main module imports and initializes the following dependencies:Core Libraries
- Alpine.js - The reactive framework powering the theme
- flying-pages-module - Prefetches pages for faster navigation
Alpine.js Plugins
@alpinejs/intersect- Intersection Observer integration@alpinejs/collapse- Collapse/expand animations@alpinejs/focus- Focus management utilities
Internal Modules
debugLog- Debug logging utilityloadScript- Dynamic script loaderdataDOM- Alpine.data component for DOM utilities
Implementation
Alpine.js Setup
The main.js file exposes Alpine globally and registers plugins before initialization:DOM Ready Helper
The file includes adomReady() helper function that executes callbacks when the document is ready:
Conditional Script Loading
For Safari browsers, the balance-text library is loaded dynamically:Initialization Sequence
When the DOM is ready, the following initialization occurs:Console Branding
The main.js file outputs styled console messages displaying the FreshJuice branding:- Cocktail emoji (🍹) in large format
- “Fresh Juice” title with custom styling
- Theme description
- GitHub repository link
Usage
This file is automatically loaded as part of the theme’s build process. No manual initialization is required.Plugin Registration Order
Related
- debugLog - Debug logging utility
- loadScript - Dynamic script loader
- Alpine.data (xDOM) - DOM utility component