Module2 PartB
Module2 PartB
Local storage
Web Workers are a feature in HTML5 that allow you to run scripts in
the background, separate from the main execution thread of a web
fi
page. They enable multitasking and parallel processing in web
applications, improving overall performance and responsiveness.
• Service Workers:
• Service Workers are a crucial part of building of ine-
capable web applications. They are JavaScript les that
run in the background, separate from the main browser
thread.
• Service Workers can intercept and handle network
requests, allowing developers to implement caching
strategies.
• They enable features like background synchronization,
push noti cations, and of ine support.
Caching Strategies:
• Caching is a key aspect of of ine web applications. By caching
resources, such as HTML, CSS, JavaScript, and images, you
can ensure that these assets are available even when the user
is of ine.
• Different caching strategies include:
• Cache First: Serve the resource from the cache, and if
it's not there, fetch it from the network.
• Network First: Attempt to fetch the resource from the
network, and if that fails, fall back to the cache.
• Network Only: Always fetch the resource from the
network and don't use the cache.
• Cache Only: Always use the cache and don't make a
network request.
Web Storage (localStorage, sessionStorage):
• Web Storage allows the storage of key/value pairs locally in
the user's browser.
• While localStorage persists even when the browser is closed
and reopened, sessionStorage is available only for the
duration of the page session
13. Geo-location
• navigator.geolocation Object:
• The navigator.geolocation object is the main entry
point for the Geolocation API.
• It provides methods for obtaining the device's current
location and watching for changes in position.
• getCurrentPosition() Method:
• The getCurrentPosition() method is used to
asynchronously request the current location of the device.
• It takes two callback functions as parameters: one for
success (successCallback) and one for handling errors
(errorCallback).
• watchPosition() Method:
• The watchPosition() method is used to continuously
monitor the device's location.
• It also takes success and error callback functions, similar
to getCurrentPosition().
• The method returns a unique ID that can be used to later
stop watching the position using clearWatch().
• Position Object:
• The position information is represented by a Position
object, which contains details such as latitude, longitude,
altitude, accuracy, and timestamp.
14. Path
In this example:
15. Texts
In HTML, you can use the <text> element to display text content.
However, in most cases, the <text> element is not directly used for
this purpose. Instead, the common way to display text in HTML is
by using the <p>, <h1> through <h6>, <span>, or other text-related
elements.
Gradients:
You can create gradients using the CSS linear-gradient and
radial-gradient properties. Here's a simple example using
JavaScript to apply a linear gradient to the background of an HTML
element:
<!D<!DOCTYPE html>
<html lang="en">
<head>
<style>
fi
#gradientDiv {
width: 300px;
height: 200px;
}
</style>
<title>Gradient and Images in JavaScript</title>
</head>
<body>
<div id="gradientDiv"></div>
<script>
// JavaScript to apply linear gradient dynamically
var gradientDiv =
document.getElementById('gradientDiv');
gradientDiv.style.background = 'linear-gradient(to
right, #ff7e5f, #feb47b)';
</script>
</body>
</html>OCTYPE html>
<html lang="en">
Images
<!DOCTYPE html>
<head>
</head>
<body>
<img id="myImage" src="initial-image.jpg" alt="Initial Image"
width="300" height="200">
<script>
myImage.src = 'new-image.jpg';
</script>
</body>
</html>
<div id="gradientDiv"></div>
<script>
// JavaScript to apply linear gradient dynamically
var gradientDiv = document.getElementById('gradientDiv');
gradientDiv.style.background = 'linear-gradient(to right, #ff7e5f, #feb47b)';
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#gradientDiv {
width: 300px;
height: 200px;
}
</style>
<title>Gradient and Images in JavaScript</title>
</head>
<body>
<div id="gradientDiv"></div>
<script>
// JavaScript to apply linear gradient dynamically
var gradientDiv = document.getElementById('gradientDiv');
gradientDiv.style.background = 'linear-gradient(to right, #ff7e5f, #feb47b)';
</script>
</body>
</html>