MMC2025 - Web Application Development - Module 1 - Introduction to Web Development and HTML5 - Class
MMC2025 - Web Application Development - Module 1 - Introduction to Web Development and HTML5 - Class
Department of MCA
• Web Servers:
Computers that host websites and other web content, delivering it to users'
browsers.
• URLs (Uniform Resource Locators):
Address that identifies the location of a specific resource on the web, such
as a web page or image.
• HTML (Hypertext Markup Language):
The standard language for creating web pages, defining the structure and
content.
• CSS (Cascading Style Sheets):
Used to style web pages, controlling the layout, colors, and fonts.
• JavaScript:
A programming language used to add interactivity and dynamic behavior
to web pages.
• Protocols:
Rules that govern how data is transmitted over the internet, such as HTTP
(Hypertext Transfer Protocol) for web pages and FTP (File Transfer Protocol)
for file uploads.
Examples of Web Protocols:
• HTTP (Hypertext Transfer Protocol):
The foundation of the web, used to transfer data between clients (web
browsers) and servers (web hosts).
• HTTPS (Hypertext Transfer Protocol Secure):
The secure version of HTTP, encrypting data transmission to protect
sensitive information.
• FTP (File Transfer Protocol):
Used to transfer files between computers, such as uploading website
files to a server.
• TCP/IP (Transmission Control Protocol/Internet Protocol):
A suite of protocols that provide the foundation for the internet, ensuring
reliable data transmission.
Introduction
In today’s connected world, almost every online service we use relies on a
foundational model called client-server architecture. From loading web
pages to using mobile apps, this structure powers the way clients (users)
interact with servers (data providers). In this article, we’ll break down what
client-server architecture is, its components, types, and real-life
applications. We’ll also include easy-to-understand examples and diagrams to
help clarify this crucial tech concept.
Conclusion
In summary, client-server architecture is a critical concept in modern
software development. This model powers countless applications by efficiently
handling requests between clients and servers. By exploring real-life
examples, diagrams, and practical scenarios, you’ll be better equipped to
understand, design, and work with this fundamental architecture.
Frontend Development
The frontend is the part of a website or web application that users directly
interact with. It includes everything visible on the screen, such as the layout,
design, and interactive features. The frontend is responsible for creating a
smooth, attractive, and user-friendly experience. It’s called the client-side
because it runs on the user’s browser.
• User Interface (UI) Design: Frontend development focuses on
designing the look of a website, including layout, colors, typography,
and interactive elements.
• Responsiveness: Ensures that websites work well on various devices
and screen sizes, providing a seamless experience on desktops, tablets,
and smartphones.
• Interactivity: It implements interactive features like buttons, forms,
animations, and dynamic content that engage users.
• Cross-Browser Compatibility: Ensures that the website functions
correctly across different web browsers, such as Chrome, Firefox, and
Safari.
Frontend Technologies
Frontend development uses various technologies to create the user interface
(UI) and user experience (UX). Some of the most common frontend
technologies include:
• HTML (Hypertext Markup Language): The standard language for
creating the structure of web pages. It defines elements such as
headings, paragraphs, links, and images.
• CSS (Cascading Style Sheets): Used for styling HTML
elements. CSS controls the layout, colors, fonts, and responsiveness of
a webpage.
• JavaScript: A programming language that adds interactivity to the
web. JavaScript is used to create dynamic content, such as forms,
animations, and interactive maps.
• Frontend Frameworks: React, Angular, Tailwind, Bootstrap,
and Vue.js.
• Frontend Libraries: jQuery and SASS.
Backend Development
The Backend refers to the server side of web development. It is responsible
for handling and processing data, storing and retrieving information, and
ensuring that the frontend has the necessary data to function properly. While
users interact with the frontend, the backend works behind the scenes to
handle the business logic and data management.
• Server-Side Logic: Backend development handles the server-side
operations, including processing data, managing application logic, and
handling user requests.
• Database Management: Manages and interacts with databases
(e.g., MySQL, PostgreSQL, MongoDB) to store, retrieve, and update
data based on user interactions.
• API Development: Creates and manages APIs (Application
Programming Interfaces) to allow communication between the frontend
and backend or with other external services.
Backend Technologies
Backend development uses various technologies to handle the server-side
logic and data management. Some of the most popular backend technologies
include:
• Programming Languages: Common languages for backend
development include PHP, Python, Ruby, Node.js, Java, and C#.
• Databases: Backend systems interact with databases to store and
retrieve data. Popular databases include MySQL, PostgreSQL, MongoDB,
and SQLite.
• Web Servers: Web servers like Apache, Nginx, and IIS are used to
handle HTTP requests and deliver content to users.
• Backend Frameworks: Django (Python), Ruby on Rails
(Ruby), Express.js (Node.js), and Spring Boot (Java).
• Backend Libraries: Mongoose, Socket.io, JDBC, Pandas.
Frontend vs Backend
• Below is the difference between front-end and back-end developers.
Frontend Backend
Refers to the client-side of the Refers to the server side of the web
web application. application.
Frontend Backend
Full-stack Development
Full-stack development refers to the development of both the frontend (client-
side) and backend (server-side) parts of a web application. A full-stack
developer is skilled in both areas and can build a complete web application
from start to finish.
• Frontend Development: Involves creating the user interface (UI),
that users interact with directly on the web page, using technologies like
HTML, CSS, JavaScript, and frontend frameworks like React or Angular.
• Backend Development: Involves working with the server-side,
databases, and the application logic that powers the website or app.
Backend developers use languages like Python, PHP, Ruby, Java, and
frameworks like Django, Spring or Node.js.
• Databases: Full-stack developers often work with databases to store
and manage data. This can involve SQL-based databases like MySQL or
PostgreSQL, or NoSQL databases like MongoDB.
• Server Management: They are also responsible for configuring and
managing servers, ensuring that the website or application is hosted
and running efficiently.
Conclusion
Frontend and backend development are two sides of the same coin, each
playing a crucial role in web development. Frontend developers create the
interface that users interact with, while backend developers ensure that the
underlying data, logic, and functionality work properly. Understanding both
frontend and backend development is essential for anyone looking to pursue
a career in web development. Whether you focus on one side or become a
full-stack developer, mastering the tools and technologies for both is key to
building robust and scalable web applications.
Department of MCA
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Simple HTML Page</title>
</head>
<body>
<header>
<h1>Hello, World!</h1>
</header>
<main>
<p>This is a simple HTML5 page.</p>
</main>
<footer>
<p>@Prof. Rajesh N, Dept. of MCA, AMCEC - All rights
reserved</p>
</footer>
</body>
</html>
Features of HTML5
HTML5 introduces several new elements and attributes to improve web
development:
• Semantic Elements:
o New tags like <article>, <aside>, <nav>, <header>, <footer>,
and <section> provide meaning and structure to the content,
improving both accessibility and SEO.
• Multimedia Support:
o Native support for <audio> and <video> tags removes the need
for third-party plugins like Flash.
• Canvas API:
o Allows drawing graphics, animations, and games directly in the
browser using JavaScript.
• Geolocation API:
o Provides access to the user’s geographical location (with
permission), enabling location-based services.
• Web Storage (localStorage and sessionStorage):
o Local storage (localStorage) and session storage (sessionStorage)
provide client-side data storage, improving performance and
enabling offline functionality.
• Web Workers:
o Allows background processing of JavaScript, improving
performance by preventing blocking of the main thread.
• Form Enhancements:
o New input types (e.g., date, email, number) and form validation
make forms easier and more efficient to create.
• Drag and Drop API:
o Allows users to drag and drop elements within a web page or
between applications, enhancing interactivity.
• SVG Integration:
o Improved support for Scalable Vector Graphics (SVG), allowing for
resolution-independent vector graphics to be embedded directly
into HTML.
• WebSocket API:
o Enables real-time, bidirectional communication bet.
Deprecated Elements in HTML5
HTML5 has removed several outdated elements, replacing them with newer,
more flexible solutions:
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
<center> CSS
<dir> <ul>
<font> CSS
<frame> None
<frameset> None
<noframes> None
<isindex> None
<tt> CSS
HTML5 Advantages
• Multimedia Support: Native audio and video tags for easier media
embedding.
• Better Performance: Faster loading times with fewer dependencies.
• Cross-Platform: Works across all major browsers and mobile devices.
• Geolocation: Access users’ location for location-based features.
• Offline Capability: Works offline with Web Storage and AppCache.
• Simplified Code: New semantic tags for cleaner, more readable code.
• Mobile-Friendly: Optimized for a smoother mobile experience.
HTML5 Disadvantages
• Browser Inconsistencies: Older browsers may not fully support
HTML5 features.
• Mobile Compatibility: Some older mobile devices may struggle with
certain HTML5 features.
• Security Risks: New features like Web Storage can potentially expose
user data if not handled properly.
• Complexity: Advanced features like WebSockets and APIs can be
challenging for beginners.
• Lack of Support in Older Internet Explorer Versions: Some older
versions of IE (like IE 8 and below) do not support HTML5 at all.
of a document and the figure goes with the flow of the document and if
it is removed it should not affect the flow of the document.
• <header>: It contains the section heading as well as other content,
such as a navigation links, table of contents, etc.
• <footer>: The <footer> tag in HTML is used to define a footer of HTML
document. This section contains the footer information (author
information, copyright information, carriers etc.). The footer tag is used
within body tag. The <footer> tag is new in the HTML 5. The footer
elements require a start tag as well as an end tag.
• <main>: Delineates the main content of the body of a document or
web app.
• <mark>: The <mark> tag in HTML is used to define the marked text.
It is used to highlight the part of the text in the paragraph.
• <nav>: The <nav> tag is used to declaring the navigational section in
HTML documents. Websites typically have sections dedicated to
navigational links, which enables user to navigate the site. These links
can be placed inside a nav tag.
• <section>: It demarcates a thematic grouping of content.
• <details>: The <details> tag is used for the content/information which
is initially hidden but could be displayed if the user wishes to see it. This
tag is used to create interactive widget which user can open or close it.
The content of details tag is visible when open the set attributes.
• <summary>: The <summary> tag in HTML is used to define a
summary for the <details> element. The <summary> element is used
along with the <details> element and provides a summary visible to the
user. When the summary is clicked by the user, the content placed inside
the <details> element becomes visible which was previously hidden.
The <summary> tag was added in HTML 5. The <summary> tag
requires both starting and ending tag.
• <time>: The <time> tag is used to display the human-readable
data/time. It can also be used to encode dates and times in a machine-
readable form. The main advantage for users is that they can offer to
HTML Attributes
The complete list of HTML attributes are given below.
Attributes: Description
Attributes: Description
Attributes: Description
Specify the date and time of the inserted and the deleted
datetime
text.
Attributes: Description
Attributes: Description
Attributes: Description
The user cut or delete the content that has been present
oncut
in the element.
The number of visible text lines for the control i.e the
rows
number of rows to display.
Attributes: Description
Specify the initial width for the input field and a number
size
of visible rows for the select element.
start The start value for numbering the individual list item.
6. <footer>
7. <header>
8. <main>
9. <mark>
10. <nav>
11. <section>
Example:
<!DOCTYPE html>
<html>
<head>
<title>Article Tag</title>
<style>
h1 {
color: #006400;
font-size: 50px;
text-align: left;
}
p{
font-size: 25px;
text-align: left;
margin-top: 0;
}
</style>
</head>
<body>
<article>
<h1>GeeksforGeeks</h1>
<p>A Computer Science portal for geeks. It contains well
written, well thought, and well explained computer science and
programming articles, quizzes, and practice/competitive
programming/company interview questions.</p>
</article>
</body>
</html>
It is used to place content in a sidebar i.e. aside from the existing content. It
is related to surrounding content.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Aside Tag</title>
<style>
h4 {
Color:#006400;
font-size:50px;
Text-align:none;
margin-bottom:0px;
}
p{
font-size:25px;
text-align:none;
margin-top:0px;
}
</style>
</head>
<body>
<p>GeeksforGeeks is a Computer Science Portal</p>
<aside>
<h4>GeeksForGeeks</h4>
<p>GeeksforGeeks is a computer Science platform
where you can learn good programming.
</p>
</aside>
</body>
</html>
The “details” defines additional details that the user can hide or view.
“summary” defines a visible heading for a “details” element.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Detail and summary Tag</title>
<style>
.GFG {
Color:#006400;
font-size:50px;
Text-align:none;
margin-bottom:0px;
}
p{
font-size:25px;
text-align:none;
margin-top:0px;
}
</style>
</head>
<body>
<details>
<summary class="GFG">
GeeksforGeeks
</summary>
<p>GeeksforGeeks is a Computer Science portal
where you can learn good programming.
</p>
</details>
</body>
</html>
These are used to add an image to a web page with a small description.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Figcaption Tag</title>
<style>
h2 {
Color:#006400;
font-size:50px;
Text-align:none;
margin-bottom:0px;
}
p{
font-size:25px;
text-align:none;
margin-top:0px;
}
</style>
</head>
<body>
<h2>AMCEC</h2>
<figure>
<img src="AMCEC Logo..png"
alt="Logo is Not Avilable"
style="width:20%">
<figcaption>
AMCEC Logo
</figcaption>
</figure>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<head>
<title>Header Tag</title>
<style>
h1, h3 {
Color:#006400;
Text-align:left;
margin-bottom:0px;
}
p{
font-size:25px;
text-align:left;
margin-top:0px;
}
</style>
</head>
<body>
<article>
<header>
<h1>GeeksforGeeks</h1>
<h3>GeeksforGeeks</h3>
<p>A computer Science portal</p>
</header>
</article>
</body>
</html>
Footer located at the bottom of any article or document, they can contain
contact details, copyright information etc. There can be multiple footers on a
page.
<!DOCTYPE html>
<html>
<head>
<title>footer Tag</title>
<style>
p{
font-size:25px;
text-align:left;
margin-top:0px;
}
</style>
</head>
<body>
<footer>
<p>
Posted by: GeeksforGeeks
</p>
<p>
Contact:
<a href="https://www.geeksforgeeks.org">
geeksforgeeks.org
</a>.
</p>
</footer>
</body>
</html>
It defines the main content of the document. The content inside the main
tag should be unique.
Example:
<!DOCTYPE html>
<html>
<head>
<title>main Tag</title>
<style>
h1 {
color:#006400;
}
p{
font-size:25px;
text-align:none;
margin-top:0px;
}
</style>
</head>
<body>
<main>
<h1>Important Residences</h1>
<p>
<article>
<h1>Rashtrapati Bhavan</h1>
<p>
It is the home of
the President of India.
</p>
</article>
<article>
<h1>The White House</h1>
<p>
It is the home of the
President of United
States of America.
</p>
</article>
</main>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<head>
<title>section Tag</title>
<style>
h1 {
color:#006400;
}
p{
font-size:25px;
text-align:none;
margin-top:0px;
}
</style>
</head>
<body>
<section>
<h1>Data Structure</h1>
<p>
Data Structure is a data
organization and storage
format that enables efficient
access and modification.
</p>
</section>
<section>
<h1>Algorithm</h1>
<p>
A process or set of rules to
be followed in calculations
or other problem-solving
operations, especially by
a computer.
</p>
</section>
</body>
</html>
<head>
<title>nav Tag</title>
<style>
h1 {
color:#006400;
}
</style>
</head>
<body>
<h1>Navigation Bar</h1>
<nav>
<a href="/home/">
Home
</a> |
<a href="/about-us/">
About Us
</a> |
<a href="/data-structure/">
Data Structure
</a> |
<a href="/operating-system/">
Operating System
</a>
</nav>
</body>
</html>
<head>
<title>mark Tag</title>
<style>
h1 {
color:#006400;
}
</style>
</head>
<body>
<h1>mark tag</h1>
<p>
GeeksforGeeks is a
<mark>Computer Science</mark>
portal
</p>
</body>
</html>
Supported Browsers
• Google Chrome: 1
• Edge: 12
• Mozilla: 1
• Opera: 15
• Safari: 4
Elements Descriptions
Elements Descriptions
<input
Defines a password field
type="password">
<input
Defines a submit button
type="submit">
<!DOCTYPE html>
<html>
<head>
<title>Html Forms</title>
</head>
<body>
<h2>HTML Forms</h2>
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
</html>
Output:
In this example:
• HTML Structure: The code has a basic HTML structure with a title
"HTML Forms."
• Heading: The <h2> tag displays "HTML Forms" as the main heading on
the page.
• Form Tag: The <form> tag defines a form for user input.
• Username Field: A text input field for the username with a label.
• Password Field & Submit: A password input field and a submit button
to send the form data.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>HTML Form</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
form {
width: 400px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
fieldset {
border: 1px solid black;
padding: 10px;
margin: 0;
}
legend {
font-weight: bold;
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
input[type="date"] {
width: calc(100% - 20px);
padding: 8px;
margin-bottom: 10px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
.gender-group {
margin-bottom: 10px;
}
.gender-group label {
display: inline-block;
margin-left: 10px;
}
input[type="radio"] {
margin-left: 10px;
vertical-align: middle;
}
input[type="submit"] {
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>User Personal Information</legend>
<label for="name">Enter your full name:</label>
<input type="text" id="name" name="name" required />
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email" required />
<label for="password">Enter your password:</label>
</html>
Output:
HTML Forms
Example Output
Here are some of the key attributes that can be used with
the <form> element:
1. action: This attribute specifies where to send the form-data when a
form is submitted. The value of this attribute is typically a URL.
2. method: This attribute defines the HTTP method used to send the form-
data. The values can be “get” or “post”.
Media Tags:
Table of Content
• <audio> Tag
• <video>
• Adding youtube videos
• <embed>
• <source>
• <track>
1. <audio> Tag:
It is a useful tag if you want to add audio such as songs, or any sound files
into your webpage.
Syntax:
<audio>
<source src="sample.mp3" type="audio/mpeg">
</audio>
<head>
<style>
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<p>Audio Sample</p>
<!--- Autoplay ensure to run audio automatically
after running the program -->
<audio controls autoplay>
<source src=
"https://media.geeksforgeeks.org/wp-
content/uploads/20190531165842/Recording1514.ogg"
type="audio/ogg">
<source src=
"https://media.geeksforgeeks.org/wp-
content/uploads/20190531165842/Recording1514.mp3"
type="audio/mpeg">
</audio>
</body>
</html>
Output:
2. <video> Tag:
It is a standard way to embed a video into your web page.
Syntax:
<video src="" controls> </video>
Output:
<head>
<title>Page Title</title>
</head>
<body>
<iframe width="942" height="530"
src=
"https://www.youtube.com/embed/KWnoiOimNbs"
title=
"Introduction to Python | Sample Video for Python Foundation Course |
GeeksforGeeks"
frameborder="0"
allow=
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope;
picture-in-picture; web-share"
allowfullscreen>
</iframe>
</body>
</html>
Output:
4. <embed> Tag:
It is used as a container for embedding plug-ins such as flash animations.
Syntax:
<embed attributes>
Example 4: In this example, we will use <embed> tag with an example.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<p>Embed Sample</p>
<embed src=
"https://media.geeksforgeeks.org/wp-
content/uploads/20210723103530/simplescreesdfdsrecorder2021071.gif"
width="300px" height="300px">
</body>
</html>
5. <source> Tag:
As you can observe that <audio>, <video> elements contain the <source>
element, the <source> tag is used to attach multimedia files.
Syntax:
<source src="" type="">
...
</source>
Example 5: In this example, we will use <source> tag with an example.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
}
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h2>Source Tag</h2>
<audio controls>
<source src="audio.mp3"
type="audio/mp3">
</audio>
</center>
</body>
</html>
Output:
6. <track> Tag:
It is used to specify subtitles, caption files, or different files containing text,
that ought to be visible once the media is taking part in it. Thus, it is a simple
sector for the <audio> and <video> elements.
Syntax:
<track Attribute>
Example 6: In this example, we will use <track> tag with an example.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>Track Tag: Both Audio and Video</h2>
<video width="300" height="300" controls>
<source src="myvid.mp4" type="video/mp4">
<track src=
"https://contribute.geeksforgeeks.org/wp-content/uploads/11.mp4"
kind="subtitle" srclang="en"
label="English">
</video>
</body>
</html>
Output:
Department of MCA
What is SVG?
SVG (Scalable Vector Graphics) is an XML-based format used for defining two-
dimensional vector graphics on the web. Unlike raster images such as .jpg,
.gif, or .png, SVG images can be scaled to any size without losing quality.
• Scalable: SVG images maintain high quality at any resolution, making
them ideal for logos, icons, and scalable graphics.
• Editable: SVG images can be created and edited using any text editor
since they are based on XML.
• Interactive: You can modify SVG graphics using CSS or JavaScript.
Example: In this example, we will see the code for drawing a circle using SVG
elements.
<!DOCTYPE html>
<html>
<head>
<title>SVG</title>
<style>
#svgelem {
position: relative;
left: 50%;
-webkit-transform: translateX(-20%);
-ms-transform: translateX(-20%);
transform: translateX(-20%);
}
</style>
<title>HTML5 SVG</title>
</head>
<body>
<h2 align="center">
SVG Circle(Geeks For Geeks)
</h2>
</html>
Output:
The HTML5 Canvas element provides a space on the web page where you can
dynamically draw graphics using JavaScript. Unlike SVG, which is vector-
based, Canvas is pixel-based (raster).
• Pixel-based: Canvas allows you to draw shapes, images, and text pixel
by pixel.
• Dynamic: It’s ideal for real-time graphics, such as games, interactive
animations, or visual effects.
• JavaScript-based: You must use JavaScript to manipulate the canvas
and render graphics.
Example: In this example, we will see the code for drawing a square using
Canvas elements.
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Canvas Tag</title>
</head>
<body>
<h2>Canvas Square(Geeks For Geeks)</h2>
<script>
var c = document.getElementById('newCanvas');
var ctx = c.getContext('2d');
ctx.fillStyle = '#7cce2b';
ctx.fillRect(0, 0, 100, 100);
</script>
</body>
</html>
Output:
SVG Canvas
SVG has better scalability. So it can Canvas has poor scalability. Hence it
be printed with high quality at any is not suitable for printing on higher
resolution. resolution.
Conclusion
Both SVG and HTML5 Canvas are used for web-based graphics, but their
applications differ based on the use case:
• Use SVG when you need high-quality, scalable graphics like logos and
icons.
• Use Canvas when you need dynamic, real-time rendering, such as
animations or games.
Choose based on your project’s requirements, keeping in mind scalability,
performance, and interaction needs.
HTML5 APIs
HTML5 APIs are built to make web development simple and easy. They offer
ready-to-use tools for adding cool features like videos, graphics, and real-time
updates to websites without needing complex code.
Example:
<html>
<body>
<button onclick="getLocation()">Get My Location</button>
<p id="location"></p>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
document.getElementById("location").innerHTML = "Geolocation is not
supported by this browser.";
}
}
function showPosition(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
document.getElementById("location").innerHTML = `Latitude:
${latitude}<br>Longitude: ${longitude}`;
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
document.getElementById("location").innerHTML = "User denied the
request for Geolocation.";
break;
case error.POSITION_UNAVAILABLE:
document.getElementById("location").innerHTML = "Location
information is unavailable.";
break;
case error.TIMEOUT:
document.getElementById("location").innerHTML = "The request to
get user location timed out.";
break;
case error.UNKNOWN_ERROR:
document.getElementById("location").innerHTML = "An unknown
error occurred.";
break;
}
}
</script>
</body>
</html>
• Get Location: Click the button to retrieve the user's current location.
• Error Handling: Handles errors if location permission is denied or
unavailable.
• Dynamic Update: Displays latitude and longitude in the paragraph
tag.
The Web Storage API provides mechanisms by which browsers can store
key/value pairs, in a much more intuitive fashion than using cookies.
Example:
<html>
<body>
<p id="result"></p>
<script>
function saveData() {
if (username) {
localStorage.setItem("username", username);
alert("Username saved!");
} else {
function loadData() {
if (username) {
} else {
</script>
</body>
</html>
HTML is a Markup language that is used to design web pages and JavaScript
is a programming language that enables dynamic interactivity on websites
when it is applied to an HTML. It helps users to build modern web applications.
But the problem with this JavaScript was designed to run in a single-threaded
environment, so multiple scripts cannot run at the same time also when
executing Javascript scripts on an HTML page, the page becomes unresponsive
until the script is finished.
So, to overcome this Web worker comes into the picture. The Web Workers is
a separate piece of JavaScript code that runs in the background of the web
page without affecting it.
Table of Content
Web workers are multithreaded objects that are used to execute Javascript in
the background without affecting the performance of the application or
webpage. Web Workers allow for long-running scripts that are not interrupted
by scripts that respond to clicks or other user interactions and allow long tasks
to be executed without affecting the responsiveness of the web page.
Generally, it is used for big CPU-intensive tasks.
Web Workers provide a way to run scripts in the background, separate from
the main thread of your web page. They allow you to perform tasks without
interfering with the user interface. Here are the two main types of Web
Workers:
1. Dedicated Workers:
2. Shared Workers:
• Shared workers are designed for scenarios where you need to share
data or coordinate actions across different parts of your application.
• Shared workers are more versatile and can be utilized by various scripts
simultaneously.
Step 1: Create a Javascript file for Web Worker and the code which you
want to run in the background. Here we are creating a webWorker.js file
and using it to count from 1 in the background and show that to our web
page and in the frontend, we will use the alert box.
Step 2: Now create an index.html and add the following codes to that file.
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Worker</title>
</head>
<body>
<p>Web Worker is Counting Numbers</p>
<button onclick="alertMessage()">
Alert On
</button>
<script>
JavaScript Code
function timedCount() {
count = count + 1;
postMessage(count);
// It is a timeout function
setTimeout("timedCount()", 1000);
}
timedCount();
Supported Browsers:
Note: Chrome doesn't let you load Web Workers when running scripts from
a local file. So, for this use, a web host or you can use live server extension.
Implementation: Create an HTML file. Then add the manifest attribute in the
document tag of the HTML file. The manifest file contains the
extension.appcache.
<html manifest="demo.appcache">
Step 2: Add Manifest Attribute in HTML file: Before adding Cache Manifest
File in HTML check the following things:
1. Check web server is configured to serve the manifest files or not.
2. Upload the cache manifest file.
3. Add a manifest attribute to the HTML file.
<!DOCTYPE html>
<html manifest="demo.appcache">
<body text="red">
<center>
Application Cache In HTML 5.
<p>
<a href="page.html">Click Here</a>,
This page contain data even offline mode .
</p>
</body>
</html>
Output:
<body text="green">
<h3>
<center>
Welcome to GeeksForGeeks.
</center>
</h3>
</body>
</html>
Explanation: Main HTML file (index.html) contain link of next page. When the
user clicks on that link next page will execute. The main file contains a
manifest attribute so even if the user went offline and he refreshes the page
it will show the content of that page. This all works because of the application
cache.
Output:
Advantage:
• Offline Mode: Users can use applications without the internet or offline.
• Less Space: Web pages are already cached so they occupy less space.
• Increase Speed: Web pages contain cached data. cached data are local
so they load fast
• Reduced server load: The web browser will only download data if it is
updated on the server. It also decreases HTTP requests.
• Modern browser: The HTML 5 feature Cache feature is available in all
modern web browsers.
Disadvantage:
• Old browser: Not available in an older version of HTML.