Writing a Single Page Application with Vanilla JS

Writing a Single Page Application with Vanilla JS

Learn how to write a Single Page Application (SPA) with Vanilla JavaScript.

Recently, I came across the following Stack Overflow question regarding state handling on refresh in a single page application (SPA). I found the approach OP was taking towards developing a SPA interesting: they wanted to avoid third party libraries and frameworks because they “prefer the simpler ways first”.

Here’s the question that sparkled this article

I’ve made a simple proof of concept to illustrate how one could achieve what they were looking for, which can be seen here (or cloned from github).

In the uploaded version, I’m using the last URL parameter to determine what should be loaded. This is standard practice, but it requires server-side configuration in order to route all your incoming requests to a single file.

The other alternative (default option of the code on github) is using the anchor fragment. My script supports both alternatives, and you can see here the uploaded version that uses anchors instead of URL rewriting.

The code is pretty simple (though it could be further simplified by using fetch or a less verbose XHR implementation).


javascript vue reactjs html web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

ReactJS: The Javascript Developer’s Guide

This article will walk you through the concepts you would need to know to step into the world of widely used ReactJS.

Vue.js Web App Development | Skenix Infotech

Our expert Vue.js developers follows Agile methodology that delivers high-quality & affordable Vue.js services. Hire Vue.js Developer from Skenix Infotech.

ReactJS Web App Development Services

We provide top-notch ReactJS development services to global clients. Hire expert ReactJS developers from top React JS development company, Skenix Infotech.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Top Reasons to Choose ReactJS for Web App Development - TopDevelopers.co

ReactJS, a JavaScript library that helps developers to build SEO Friendly web apps. Get to know more about ReactJS and why it is a good option for your next project.