Chapter 5 - JavaScript Framework
Introduction
Section titled βIntroductionβChapter 5 covers the JavaScript framework powering the NETWRIX website π. This custom architecture, built by Terra, combines modern tools like SWUP, GSAP, and Boostify to deliver seamless page transitions, optimized performance, and modular code organization.
Think of the JavaScript framework as the nervous system of the website - coordinating smooth animations, managing component lifecycles, and ensuring optimal performance across all user interactions.
What is the JavaScript Framework?
Section titled βWhat is the JavaScript Framework?βThe NETWRIX JavaScript framework is a performance-focused architecture built on three core pillars:
- Modular Structure - Components, handlers, and utilities organized for reusability
- Performance Optimization - Strategic code splitting and lazy loading
- Smooth Transitions - SWUP-powered page transitions with coordinated animations
Key Characteristics:
- π― SWUP Integration: SPA-like navigation with SEO-friendly server-rendered HTML
- π Handler System: Consistent lifecycle management for all components
- π Manager Registry: Centralized instance and library management
- π¨ GSAP Animations: High-performance, timeline-based motion design
- πͺ Lazy Loading: Boostify-powered on-demand component loading
Location in Code: src/scripts/
Structure:
src/scripts/βββ Project.js # Entry point & initializationβββ Core.js # SWUP controllerβββ Main.js # Application controllerβββ handler/ # Component lifecycle managersβββ module/ # Component classesβββ motion/ # Animations (heroes, reveals, transitions)βββ preload/ # Asset management & loading strategyβββ utilities/ # Helper functionsFramework Topics
Section titled βFramework TopicsβExplore each framework topic in detail:
Learn about the three core files (Project.js, Core.js, Main.js), SWUP integration, and how the framework orchestrates page transitions and component initialization.
Understand Terraβs strict class conventions, the four pillars of component architecture (constructor, init, events, destroy), and how to build SWUP-compatible components.
Master the Handler pattern for managing component lifecycle, learn about the Manager registry, and discover how handlers coordinate with SWUP transitions.
Explore GSAP integration, page transition animations, hero reveals, scroll-triggered effects, and the coordinated animation system.
Discover the complete catalog of internal Terra libraries and external packages used in NETWRIX, including their purpose and usage patterns.
Quick Start Guide
Section titled βQuick Start GuideβFor New Developers
Section titled βFor New DevelopersβIf youβre new to the NETWRIX JavaScript framework, follow this learning path:
- Start with Overview β Understand the three core files and SWUP lifecycle
- Learn Classes β Master the component structure conventions
- Practice Handlers β Build lifecycle-aware components
- Explore Animations β Implement GSAP-based motion design
- Review Libraries β Familiarize yourself with available tools
Common Questions
Section titled βCommon QuestionsβQ: Whatβs the difference between Project.js, Core.js, and Main.js?
- Project.js: Entry point, loads libraries, runs preloader
- Core.js: SWUP controller, manages page transitions
- Main.js: Application controller, initializes all handlers
Q: How do I create a new component?
- Create the component class following Terraβs structure
- Add it to
extraAssets.jsfor lazy loading - Create a Handler to manage its lifecycle
- Register the Handler in
Main.js - Allocate instance pool in
Project.js
Q: Why use Handlers instead of direct instantiation?
- Handlers ensure components are properly destroyed on page transitions
- They integrate with Boostify for performance optimization
- They provide consistent patterns across the codebase
- They prevent memory leaks in SWUP navigation
Q: How do I debug the framework?
- Add
?debugto any URL to enable debug mode - Check console for library loading logs
- Inspect
Manager.instancesto view active components - Use SWUP debug plugin to trace lifecycle events
Framework Architecture
Section titled βFramework ArchitectureβThe Three Core Files
Section titled βThe Three Core Filesβββββββββββββββββ Project.js β β Entry point, loads libraries, preloaderββββββββ¬βββββββ β βΌββββββββββββββββ Core.js β β SWUP controller, page transitionsββββββββ¬βββββββ β βΌββββββββββββββββ Main.js β β Application controller, handlersββββββββ¬βββββββ β βΌββββββββββββββββββββββββββββββββββββ Handlers (30+ instances) ββ - SliderHandler ββ - ModalHandler ββ - AlgoliaHandler ββ - etc. ββββββββββββββββββββββββββββββββββββComponent Lifecycle Flow
Section titled βComponent Lifecycle Flowβ1. Initial Page Load Project.js β loads GSAP, Boostify β Main.js β initializes handlers β Handlers β create component instances β Components β rendered and functional
2. User Clicks Link SWUP intercepts navigation β MitterWillReplaceContent event β Handlers β destroy instances β Out animation plays β SWUP fetches new page β Content replaced β In animation plays β MitterContentReplaced event β Handlers β create new instancesKey Concepts
Section titled βKey ConceptsβSWUP Integration
Section titled βSWUP IntegrationβSWUP enables SPA-like navigation while maintaining SEO benefits:
- No full page reloads - Content swaps via AJAX
- Server-rendered HTML - SEO-friendly, no client routing
- Lifecycle hooks - Control over content replacement
- Animation coordination - Smooth transitions between pages
- Script execution - Re-run page-specific scripts
Manager System
Section titled βManager SystemβThe Manager provides centralized registry for:
- Library References - GSAP, ScrollTrigger, Boostify, etc.
- Component Instances - All active sliders, modals, etc.
- Instance Pools - Pre-allocated arrays for each type
- Memory Management - Clean destruction prevents leaks
Handler Pattern
Section titled βHandler PatternβHandlers bridge the framework and components:
- Lifecycle Management - Init and destroy across transitions
- Smart Loading - Instant or lazy via Boostify
- Instance Tracking - Register with Manager
- Event Coordination - Listen to framework events
Performance Strategy
Section titled βPerformance StrategyβCode splitting and lazy loading optimize performance:
- Critical libraries - Loaded immediately (GSAP, Boostify)
- Above-fold components - Loaded instantly
- Below-fold components - Loaded on scroll proximity
- Third-party scripts - Deferred after page load
Framework Workflow
Section titled βFramework WorkflowβCreating a New Component
Section titled βCreating a New ComponentβWhen building a new interactive element:
-
Create Component Class
- Follow Terraβs four-pillar structure
- Store DOM references in
this.DOM - Implement
init(),events(),destroy()
-
Add to extraAssets.js
- Define library name and import path
- Specify DOM selector for auto-detection
-
Create Handler
- Extend
CoreHandler - Listen to
MitterContentReplacedandMitterWillReplaceContent - Use
assignInstances()for creation
- Extend
-
Register Handler
- Add to
Main.jsinitialization - Allocate instance pool in
Project.js
- Add to
-
Test Lifecycle
- Verify component works on initial load
- Test navigation (creation/destruction)
- Check for memory leaks with debug mode
Debug Mode
Section titled βDebug ModeβEnable framework debugging by adding ?debug to the URL:
https://netwrix.com/page?debugDebug Features:
- β SWUP lifecycle event logging
- β Library loading notifications
- β Instance creation/destruction tracking
- β Terra debugger UI for QA feedback
- β Performance timing information
Console Output Examples:
β
library Slider was in managerπ§ loading library Modalβ° Boostify - loading library VideoPlayerβ Destroying Slider instancesBest Practices
Section titled βBest Practicesββ Doβs
Section titled ββ Doβsβ-
Use the Manager for all library references
const gsap = Manager.getLibrary("GSAP").gsap; -
Follow Handler pattern for all components
class MyHandler extends CoreHandler { } -
Implement destroy() in every component class
destroy() {this.removeEventListeners();this.cleanup();} -
Leverage Boostify for below-fold components
boostify.scroll({ distance: 50, callback: () => {} }); -
Use emitter events for lifecycle coordination
this.emitter.on("MitterContentReplaced", () => {});
β Donβts
Section titled ββ Donβtsβ- Donβt bypass the Handler system - it ensures consistency
- Donβt forget destroy methods - causes memory leaks
- Donβt load all libraries upfront - use code splitting
- Donβt manipulate SWUP directly - extend Core.js instead
- Donβt skip instance pool allocation - required in Project.js
Framework Principles
Section titled βFramework PrinciplesβModular Architecture
Section titled βModular ArchitectureβEvery piece of functionality is isolated and reusable:
- Components are self-contained classes
- Handlers manage component lifecycles
- Utilities provide shared functionality
- Animations are separate, composable modules
Performance First
Section titled βPerformance FirstβOptimization is built into the architecture:
- Code splitting reduces initial bundle size
- Lazy loading defers non-critical components
- Memory management prevents leaks
- GSAP provides hardware-accelerated animations
Developer Experience
Section titled βDeveloper ExperienceβThe framework prioritizes maintainability:
- Consistent patterns reduce cognitive load
- Clear separation of concerns
- Centralized management simplifies debugging
- Extensive documentation aids learning
Next Steps
Section titled βNext StepsβOnce youβve mastered the JavaScript framework, youβre ready to build complex interactive features.
Recommended Learning Path:
- π Read Framework Overview to understand the architecture
- π― Study Classes Structure to learn component patterns
- π Master Handlers System for lifecycle management
- π¬ Explore GSAP Animations for motion design
- π¦ Review Libraries to see available tools
Framework Resources
Section titled βFramework Resourcesβ- Source Code:
src/scripts/ - Handler Template:
src/scripts/handler/_handlerFolder/Handler.js - Asset Management:
src/scripts/preload/extraAssets.js - SWUP Documentation: https://swup.js.org/
- GSAP Documentation: https://greensock.com/docs/
- Boostify Documentation: https://www.npmjs.com/package/boostify
Summary
Section titled βSummaryβThe NETWRIX JavaScript framework provides:
β
Seamless Navigation - SPA-like experience with SEO benefits
β
Smooth Animations - GSAP-powered 60fps motion design
β
Optimal Performance - Code splitting and lazy loading
β
Clean Architecture - Consistent, maintainable patterns
β
Memory Safety - Proper lifecycle management prevents leaks
By mastering this framework, you ensure that every interactive feature you build integrates seamlessly with the existing architecture, maintains high performance, and follows established best practices.
π― Key Takeaway: The framework handles the complexity of page transitions, component lifecycle, and performance optimization - allowing you to focus on building great user experiences.
Happy coding! π