8 Client Side Technologies And Single Page Applications

NET Centric Computing · Unit 8

Client-Side Technologies and Single Page Applications

Exam-focused notes for Client-Side Technologies and Single Page Applications (NET Centric Computing, BIT351): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Client-Side Technologies and Single Page Applications in short

Modern web apps often run most of their logic in the browser and talk to a server through APIs. This chapter covers single page applications, the React and Angular frameworks, REST and JSON.

Client-Side Technologies and Single Page Applications: notes

Single Page Application significance

A Single Page Application (SPA) loads one HTML page once. After that, JavaScript changes the content of the page and fetches data from the server in the background. The browser does not reload the whole page when the user clicks a link.

In a normal multi page site, every click asks the server for a full new HTML page. In an SPA, only the needed data (usually JSON) is fetched, and the page updates in place.

Significance of SPA:

  • Fast and smooth feel, like a desktop or mobile app.
  • Less data moves over the network, since only data is sent, not full pages.
  • Clear split between front end (UI) and back end (API).
  • One API can serve a web app, a mobile app and other clients.
  • Easy to work with offline caching and installable apps (PWA).

SPA uses and benefits

Where SPAs are used: email clients, dashboards, social networks, online editors, chat apps and admin panels.

Benefits:

  • Better user experience, with no full page flicker.
  • Faster page changes after the first load.
  • Reuse of the same backend API for many clients.
  • Front end and back end teams can work separately.
  • Components can be reused.

Drawbacks:

  • The first load can be slow, because a large JavaScript bundle must be downloaded.
  • Search engine optimization (SEO) is harder, unless server side rendering is used.
  • It needs JavaScript. If it is turned off, the app does not work.
  • The browser history and state need careful handling.
  • More security care is needed, since much logic runs on the client.

Popular SPA tools are React, Angular and Vue.

React framework fundamentals

React is a JavaScript library from Meta for building user interfaces. A page is built from small reusable pieces called components. React uses JSX, a syntax that looks like HTML inside JavaScript. It keeps a virtual DOM (a light copy of the page) and updates only the parts that changed.

Core ideas:

  • Component: a function that returns JSX.
  • Props: inputs passed from a parent to a child. They are read only.
  • State: data that belongs to a component. When it changes, the component draws again. The useState hook creates state.
  • Hooks: functions such as useState and useEffect that add features to function components.
  • Events: handled with attributes such as onClick and onChange.
import { useState } from "react";

function Counter({ start }) {
  const [count, setCount] = useState(start);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Add</button>
    </div>
  );
}

export default Counter;

What this unit covers

  • Single Page Application significance
  • SPA uses and benefits
  • React framework fundamentals
  • React form creation
  • React email and phone validation
  • Angular framework usage
  • REST API integration
  • JSON format and advantages

React form creation

2081 · 5 marks

Create a form using React with your own assumption. [5]

  • A User Registration Form with fields: Name, Email, Password, and Gender. - Using React functional component with useState hook for state management. - Basic form validation on submit. --- --- Concept Purpose ------ useState Manages form data, errors, and submission state handleChange Updates st...
Open this answer on its own page →

2081.1 · 5 marks

How do you create form using React? Illustrate with an example. [5]

In React, forms are handled differently from regular HTML forms. React uses controlled components to manage form data, where form input values are controlled by the component's state. --- A controlled component is an input element whose value is driven by React state. Every state mutation has an ...

Open this answer on its own page →

Single Page Application significance

2080 · 10 marks

What re the signigicances of Single Page Application? How do you integrate REST API calls? Describe.[10]

Note: No specific curriculum notes were found for this topic. The answer below is based on standard, correct web development knowledge appropriate for BSc CSIT level. --- A Single Page Application (SPA) is a web application that loads a single HTML page and dynamically updates the content as the ...

Open this answer on its own page →

Angular framework usage

2080 · 5 marks

Discuss the use of Angular with an example. [5]

Angular is a TypeScript-based open-source front-end web application framework developed and maintained by Google. It is used to build dynamic, single-page applications (SPAs) by extending HTML with additional attributes and binding data to HTML using expressions. Note: Reference notes were not av...

Open this answer on its own page →

JSON format and advantages

0 · 5 marks

Discuss about the advantages of using JSON. [5]

(Note: The reference notes did not contain specific content on this topic. The following answer is based on standard, correct Computer Science knowledge about JSON.) --- JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that is easy for humans to read and writ...

Open this answer on its own page →

SPA uses and benefits

0 · 5 marks

What is the use of SPA? Elaborate. [5]

Show solved answer

Use of SPA (Single Page Application)


What is SPA?

A Single Page Application (SPA) is a web application that loads a single HTML page and dynamically updates the content as the user interacts with the app, without reloading the entire page from the server.

Examples: Gmail, Google Maps, Facebook, Twitter


Uses / Purposes of SPA

1. Fast and Responsive User Experience

  • SPA loads the page only once; subsequent interactions update only the required portion of the page.
  • This eliminates full page reloads, making the application feel fast and fluid like a desktop app.

2. Reduced Server Load

  • Only data (JSON/XML) is exchanged between client and server after the initial load.
  • The server does not need to render full HTML pages repeatedly, reducing bandwidth and server processing.

3. Better User Interaction

  • SPA provides a seamless navigation experience.
  • Users do not experience blank screens or flickering during page transitions.

4. Separation of Frontend and Backend

  • SPA promotes a clean separation between the UI (frontend) and business logic (backend via APIs/REST).
  • Frontend frameworks like React, Angular, Vue.js are commonly used to build SPAs.

5. Offline Capability

  • SPAs can work offline or with poor connectivity using browser caching and service workers (Progressive Web Apps).

6. Easy Debugging and Testing

  • Developer tools in browsers allow easy inspection of network calls and component states.
  • Frontend and backend can be tested independently.

7. Reusability

  • The same backend API can serve the SPA as well as mobile applications, promoting code reuse.

How SPA Works (Brief)

User visits URL
      |
Browser loads single HTML + CSS + JS bundle
      |
User clicks/interacts
      |
JavaScript handles routing (client-side routing)
      |
AJAX/Fetch call to server API (returns JSON)
      |
DOM is updated dynamically (no full reload)

Limitations (for completeness)

  • Poor SEO by default (search engines may not index dynamic content easily).
  • Initial load time can be slow due to large JS bundles.
  • Requires JavaScript to be enabled in the browser.

Summary Table

FeatureSPATraditional Web App
Page ReloadNoYes
SpeedFastSlower
Server LoadLessMore
SEODifficultEasy
User ExperienceSmoothFlickering

In conclusion, SPA is widely used in modern web development because it provides a fast, interactive, and seamless user experience by dynamically rendering content on the client side without full page reloads.

Open this answer on its own page →

React email and phone validation

0 · 5 marks

Write a program to validate email id and phone number using React. [5]

Show solved answer

React Program to Validate Email ID and Phone Number

Given

This is a programming/implementation question, not a numerical problem. There is no numeric data (no matrices, burst times, page strings, etc.) to extract.

Requirements from the question:

  • Framework: React
  • Validate: Email ID and Phone Number
  • Marks: 5 (implies a complete working component with validation logic)

No numeric inputs are missing because none are required for this task.


STEP 2 - SOLVE: Model Answer

The standard approach uses functional components with the useState hook, controlled inputs, and regular expressions for validation.

import React, { useState } from 'react';

function ValidationForm() {
  const [email, setEmail] = useState('');
  const [phone, setPhone] = useState('');
  const [emailError, setEmailError] = useState('');
  const [phoneError, setPhoneError] = useState('');
  const [successMsg, setSuccessMsg] = useState('');

  // Email validation using RegEx
  const validateEmail = (value) => {
    const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    if (!value) return 'Email is required.';
    if (!emailRegex.test(value)) return 'Invalid email format.';
    return '';
  };

  // Phone validation (10-digit number)
  const validatePhone = (value) => {
    const phoneRegex = /^[0-9]{10}$/;
    if (!value) return 'Phone number is required.';
    if (!phoneRegex.test(value)) return 'Phone must be exactly 10 digits.';
    return '';
  };

  const handleSubmit = (e) => {
    e.preventDefault();
    const emailErr = validateEmail(email);
    const phoneErr = validatePhone(phone);
    setEmailError(emailErr);
    setPhoneError(phoneErr);

    if (!emailErr && !phoneErr) {
      setSuccessMsg('Email and Phone Number are valid!');
    } else {
      setSuccessMsg('');
    }
  };

  return (
    <div style={{ padding: '30px', maxWidth: '400px', margin: 'auto' }}>
      <h2>Email and Phone Validation</h2>
      <form onSubmit={handleSubmit}>
        <div style={{ marginBottom: '15px' }}>
          <label>Email ID:</label> 
          <input
            type="text"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
            placeholder="Enter your email"
          />
          {emailError && <p style={{ color: 'red' }}>{emailError}</p>}
        </div>

        <div style={{ marginBottom: '15px' }}>
          <label>Phone Number:</label> 
          <input
            type="text"
            value={phone}
            onChange={(e) => setPhone(e.target.value)}
            placeholder="Enter 10-digit phone number"
          />
          {phoneError && <p style={{ color: 'red' }}>{phoneError}</p>}
        </div>

        <button type="submit">Validate</button>
        {successMsg && <p style={{ color: 'green' }}>{successMsg}</p>}
      </form>
    </div>
  );
}

export default ValidationForm;

Explanation of Key Parts

ConceptPurpose
useStateStores input values and error/success messages
Controlled inputs (value + onChange)Keeps React state synced with input fields
e.preventDefault()Stops the browser from reloading on submit
Email regex/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ matches [email protected]
Phone regex/^[0-9]{10}$/ accepts exactly 10 digits

Email regex breakdown:

  • [a-zA-Z0-9._%+-]+ : local part (letters, digits, common symbols)
  • @ : mandatory at-symbol
  • [a-zA-Z0-9.-]+ : domain
  • \.[a-zA-Z]{2,}$ : dot + top-level domain of 2+ letters

Phone regex breakdown:

  • ^[0-9]{10}$ : ensures the string is only 10 numeric characters

Sample Behaviour

  • Input [email protected] and 9812345678 -> "Email and Phone Number are valid!" (green)
  • Input ramgmail.com -> "Invalid email format." (red)
  • Input phone 98123 -> "Phone must be exactly 10 digits." (red)
Open this answer on its own page →