DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  • Interrupt Testing: Bulletproof Your App for the Real World
  • In-App Browsers in Mobile Apps: Benefits, Challenges, Solutions

Trending

  • DZone's Article Submission Guidelines
  • Medallion Architecture: Why You Need It and How To Implement It With ClickHouse
  • A Complete Guide to Modern AI Developer Tools
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions

How Single Page Web Applications Actually Work

SPAs are all over the place but still prove a fairly controversial topic among web devs. Read on to get one developer's take on this matter.

By 
Saurabh Dashora user avatar
Saurabh Dashora
DZone Core CORE ·
Feb. 28, 19 · Analysis
Likes (5)
Comment
Save
Tweet
Share
39.9K Views

Join the DZone community and get the full member experience.

Join For Free

single page web applications have come a long way since they first appeared around 2003. they have become an integral part of the  modern javascript landscape  .

but during my discussions with quite a few developers, i feel that there is still a lack of clarity about how single-page applications actually work. hence, i decided to roll up my sleeves (figuratively speaking) and provide my take on this very very interesting subject.

so, let's start from the beginning.

what are single page applications?

the best definition, in my humble opinion, is: a single page application is a type of web application that requires only a single page to be loaded into the browser.

you might be thinking, what does this even mean? how could an application with just a single-page be of use to anyone in the world?

the answer is simple. single page web applications are built around the concept of dynamically rewriting the contents of that single page. this is different from loading pre-rendered pages from the server.

and this is where the magic happens. by taking this approach, single page web applications avoid the interruption caused by rendering the pages on the server. this removes the biggest problem the web development world usually faces with regards to providing a seamless user experience.

sounds great already, right? i know! but let's just see how all of this works and i'm sure you'll be even more amazed.

how does the magic happen?

in single-page web applications, when the browser makes the first request to the server, the server sends back the index.html file. and that's basically it. that's the only time an html file is served. the html file has a script tag for the  .js  file which is going to take control of the index.html page. all subsequent calls return just the data, usually in json format. the application uses this json data to update the page dynamically. however, the page never reloads.

the client (and not the server) handles the job of transforming data to html once the application has started. basically, most of the modern spa frameworks have a templating-engine of sorts running in your browser to generate the html.

contrast this to a traditional web application. in a traditional application, every time the application calls the server, the server will render the entire html page. the client receives the rendered page and triggers a page refresh. in this case, the browser is the client.

the below illustration explains the difference between the two approaches:

spa architecture

what are the advantages?

  • right off the bat, it's obvious that since we don't send any html over the network for every user interaction, it saves a lot of time and bandwidth. due to various opening and closing tags, the html version is usually larger. also, in the traditional approach, we also load a lot of duplicate html every time we made a request to the server. by following the spa approach, the application becomes much more responsive.
  • no marks for guessing that faster data refresh and less bandwidth consumption leads to a better user experience. this is pretty useful on mobile devices and slower internet connections.
  • there are arguments leveled against single page web applications saying that the javascript bundle size can become bloated. however, most of the good spa frameworks provide wonderful methods of code splitting. this keeps your bundle sizes in check and performs on-demand loading wherever applicable.
  • a less obvious benefit is regarding the overall architecture of an spa. using json to send application data creates a sort of separation between the view layer (html) and the application layer. this decouples the presentation and application layer and allows developers to evolve each layer independently. you can potentially replace the html markup without changing the application logic. the client and server are also totally independent of one another.
  • another overlooked benefit is production deployment of single page applications. spas are super easy to deploy. when you build an spa for production, you typically end up with one html file, one css bundle, and a javascript bundle. any static content server can host these files. good examples are nginx, amazon s3 bucket, apache, or firebase.

aren't there some disadvantages?

well, there are pros and cons to everything.

one of the biggest detractions leveled at single page web applications has been that they cannot be properly indexed by search engines like google. since there is no html markup except the initial index.html file, search engines cannot index the content because their crawlers cannot execute the javascript used to generate the html.

however, in an official  announcement  , google has stated that their search engine is now able to crawl ajax calls.

some of the criticisms leveled at spas are largely based on preference and complexity. however, in my opinion, they are largely subjective. the main point is that one should definitely look at the use-case while deciding on which approach best suits the application needs.

i would love to hear your comments on this in the comments section below.

mobile app

Published at DZone with permission of Saurabh Dashora. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  • Interrupt Testing: Bulletproof Your App for the Real World
  • In-App Browsers in Mobile Apps: Benefits, Challenges, Solutions

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!