My Journey From MVC to Modern Frontend Frameworks

Motivation

My journey into web development began with a simple curiosity about how websites and web applications work. I wanted to create interactive, user-friendly experiences and understand the technology of the websites. Learning web development allows me to bring my ideas to life, solve real-world problems, and collaborate with a community of developers. This blog documents my journey from understanding the basics of the MVC framework to exploring modern frontend frameworks that make building dynamic web applications more efficient.

What is MVC?

The Model-View-Controller (MVC) framework is an architectural pattern that separates an application into three main logical components Model, View, and Controller.


Problems with MVC


Knowing Git

Git is a version control system widely used for tracking changes in source code during software development. It allows multiple developers to work on a project simultaneously without overwriting each other's changes, facilitates collaboration, and helps manage project history.

Basic Git Commands

Initialization and Configuration:

git init: Initializes a new Git repository in the current directory.

git config --global user.name "Your Name": Sets your Git username.

git config --global user.email "you@example.com": Sets your Git email.


Cloning a Repository:

git clone : Creates a local copy of a remote repository.

Staging and Committing Changes:

git status: Displays the status of your working directory and staging area.

git add : Stages a specific file.

git add .: Stages all changes in the current directory.

git commit -m "Commit message": Commits staged changes with a descriptive message.


Branching and Merging:

git branch: Lists all branches in your repository

git branch : Creates a new branch.

git checkout : Switches to the specified branch.

git merge : Merges the specified branch into the current branch.

Viewing History and Differences:

git log: Shows the commit history.

git diff: Shows changes between the working directory and the staging area.


Push Commands

git remote add origin : Adds a remote repository and names it "origin".

git push origin : Pushes the specified branch to the remote repository named "origin".

git push -u origin : Pushes the specified branch and sets it up to track the remote branch, simplifying future pushes.

For Git documentation, visit Git!!

ServiceWorker

Service Worker is a feature, enabling developers to create more reliable web applications. They act as a proxy between the web application and the network, allowing for greater control over how network requests are handled. This includes capabilities such as caching assets for offline use, intercepting network requests, and providing seamless user experiences even when the network is unreliable. Service workers run in the background, separate from the main browser thread, and do not have direct access to the DOM. They are event-driven and typically used for features like push notifications and background data synchronization.

Basic Service Worker Syntax

                        // Service Worker registration
if ('serviceWorker' in navigator) {
    window.addEventListener('load', () => {
        navigator.serviceWorker.register('/service-worker.js')
            .then(registration => {
                console.log('Service Worker registered:', registration);
            })
            .catch(error => {
                console.error('Service Worker registration failed:', error);
            });
    });
}
                        
                    

                        // Service Worker script (sw.js)
self.addEventListener('install', event => {
    console.log('Service Worker installed');
});

self.addEventListener('activate', event => {
    console.log('Service Worker activated');
});

self.addEventListener('fetch', event => {
    console.log('Fetching:', event.request.url);
});
                        
                    

                        // Install Event
self.addEventListener('install', event => {
    console.log('Service Worker installed');
    event.waitUntil(
        caches.open(CACHE_NAME)
            .then(cache => {
                console.log('Cache opened');
                return cache.addAll([
                    '/',
                    '/index.html',
                    '/styles.css',
                    '/script.js',
                    '/images/logo.png'
                    // Add other static resources to cache as needed
                ]);
            })
    );
});
                        
                    

                        // Activate Event
self.addEventListener('activate', event => {
    console.log('Service Worker activated');
    event.waitUntil(
        caches.keys().then(cacheNames => {
            return Promise.all(
                cacheNames.map(cache => {
                    if (cache !== CACHE_NAME) {
                        console.log('Deleting old cache:', cache);
                        return caches.delete(cache);
                    }
                })
            );
        })
    );
});
                        
                    

                        // Fetch Event: Intercept network requests and serve cached resources
self.addEventListener('fetch', event => {
    console.log('Fetching:', event.request.url);
    event.respondWith(
        caches.match(event.request)
            .then(response => {
                if (response) {
                    console.log('Found in cache:', event.request.url);
                    return response;
                }
                console.log('Fetching from network:', event.request.url);
                return fetch(event.request);
            })
            .catch(error => {
                console.error('Error fetching:', error);
            })
    );
});
                        
                    

IndexDB

IndexedDB is a way for you to persistently store data inside a user's browser. Because it lets you create web applications with rich query abilities regardless of network availability, your applications can work both online and offline.

visit IndexedDB-Documentation!!!

Lighthouse

Lighthouse is an open-source, automated tool developed by Google for improving the quality of web pages. It provides audits for performance, accessibility, progressive web apps, SEO.

Key Audits in Lighthouse

Learn more about Lighthouse

Exploring Frameworks

As the web development continues to evolve, many frontend frameworks have emerged, each offering unique features and advantages to address the limitations of traditional MVC patterns. Exploring these frameworks is essential for a developer aiming to build efficient, scalable, and maintainable web applications.

Front-end Frameworks Ratios Over Time

StateOfJS

Check out the State of JS 2023 for more information!!!

Below are the some of the frameworks which I worked on!

Vite

Vite is a modern build tool that provides a fast and optimized development experience.

  • A dev server that provides rich feature enhancements over native ES modules, for example extremely fast Hot Module Replacement (HMR).
  • A build command that bundles your code with Rollup, pre-configured to output highly optimized static assets for production.

You can navigate to vite.new/{template} to select which framework to the supported template presets are:

Vite1

Use the following bun command:

bun create vite

For vite documentation, visit Vite!!

A demo of Simple Personal Finance Tracker Application

PersonalFinanceApp-Vite-github

PersonalFinanceApp-Vite click!

Performance and Lighthouse analysis

vite3 vite2

React

React is a widely-used library for building user interfaces. It emphasizes a component-based architecture, where the UI is broken down into reusable components. React's virtual DOM efficiently updates the view in response to state changes, minimizing direct DOM manipulation and enhancing performance. Its declarative syntax and strong community support make it a popular choice for complex, dynamic web applications.

PersonalFinanceApp-React-github

PersonalFinanceApp-React click!

For React documentation, visit React

Vue

Vue is a progressive framework for building user interfaces, designed to be incrementally adoptable. It offers a simple and approachable core library, along with a robust ecosystem of supporting libraries and tools. Vue's reactivity system and single-file components (combining HTML, CSS, and JavaScript) streamline development, making it an excellent choice for both small projects and large-scale applications.

PersonalFinanceApp-Vue-github

PersonalFinanceApp-Vue click!

For Vue documentation, visit Vue

Svelte

Svelte takes a different approach compared to traditional frameworks. Instead of running in the browser, Svelte shifts much of the work to compile time, producing highly efficient JavaScript code that updates the DOM surgically. This results in faster runtime performance and smaller bundle sizes. Svelte's syntax is intuitive and easy to learn, making it an attractive option for developers seeking simplicity and performance.

PersonalFinanceApp-Svelte-github

PersonalFinanceApp-Svelte click!

For Svelte documentation, visit Svelte

SolidJS

SolidJS is a declarative UI library focused on fine-grained reactivity and efficient updates. It borrows ideas from both React and Svelte, offering a syntax similar to React but with the performance benefits of a compile-time framework like Svelte. SolidJS aims to provide a highly optimized development experience with minimal runtime overhead, making it ideal for building highly interactive applications.

PersonalFinanceApp-Solid-github

PersonalFinanceApp-solid click!

For SolidJS documentation, visit SolidJS

Comparing Frameworks

React Vue Svelte SolidJS
Language JavaScript/JSX JavaScript JavaScript JavaScript/JSX
Component-Based Architecture Yes Yes Yes Yes
Reactive Programming Yes Yes Yes Yes
Single File Components No Yes Yes No
Declarative Syntax Yes Yes Yes Yes
Rendering Mechanism Virtual DOM Virtual DOM Compiler-based Fine-grained reactivity
Build Tools Create React App, Next.js Vue CLI, Vite SvelteKit, Rollup Solid Start, Vite
Performance High High Very High Very High

Conclusion

Out of all the frameworks mentioned above, i think svelte and vue frameworks are more convenient.Both Vue and Svelte offer unique advantages that make them appealing choices for modern web development.Vue’s comprehensive ecosystem, gentle learning curve, and flexible architecture make it ideal for both small projects and large-scale applications. Svelte’s performance optimizations, intuitive syntax, and compile-time reactivity offer a refreshing approach to building highly efficient web applications.

Finally, the choice of framework depends on specific project needs and developer preferences