Web Developer Notes - Page 6

JavaScript

Smooth Scrolling to Anchor Using JavaScript

Last updated: 09.10.2025
Views: 216
Smooth scrolling is a popular web design feature that enhances user experience by allowing seamless navigation between sections of a webpage. Instead of abrupt jumps, smooth scrolling creates a fluid motion, making transitions more visually appealing. In this article, we’ll explore how to implement smooth scrolling using JavaScript. It's not difficult at all to implement this. Let’s dive in and ma...
php

Caching Data to a File Using PHP

Last updated: 21.02.2026
Views: 276
Sometimes it becomes necessary to limit the number of queries to an external data source. Especially if they do not change constantly. For example, the exchange rate in the central bank. Or simply speed up the page loading, giving the script an already generated file. PHP [php] // Cache lifetime in seconds $expires = 3600; $cache_file = 'data.json'; // Some api url $url = 'h...
JavaScript

Ways to Create Objects in JavaScript

Last updated: 21.02.2026
Views: 218
There are several ways to create objects in JavaScript. The Object data type plays a critical role in JS. An object is an unordered set of key-value pairs. May contain other objects. 1. Literal notation [js] const someObject1 = {}; [/js] Perhaps the most common and easiest way. Let's add properties and methods [js] someObject1.name = "John"; someObject1.age = 25; someObject1.run...
JavaScript

How to Detect Scroll Direction on a Page Using JavaScript

Last updated: 09.10.2025
Views: 162
Sometimes it is necessary to detect the direction of vertical scrolling on a site, for example, to perform some actions with the footer or header. Let's write code to determine the direction. JavaScript [js] let lastScrollTop = 0; // Store the last scroll position window.addEventListener("scroll", function () { let scrollTop = window.pageYOffset || document.documentElement.scr...
html

How to Add a Favicon to a Website

Last updated: 21.02.2026
Views: 196
A favicon is a website icon. The easiest way to add it to the page is to put an icon with the name favicon.ico 16x16 pixels in the root of the site. Or set a path by writing one line in a section <head> HTML [html] <link rel="shortcut icon" href="/images/favicon.ico"> [/html] In today's realities, one icon is not enough. But setting all possible parameters for ...