{"id":179,"date":"2026-05-06T16:44:35","date_gmt":"2026-05-06T16:44:35","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=179"},"modified":"2026-05-06T16:44:37","modified_gmt":"2026-05-06T16:44:37","slug":"throttling","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=throttling","title":{"rendered":"Throttling"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<br>Throttling is a technique used in JavaScript to control how often a function executes over time. It is especially useful when dealing with events that fire repeatedly, such as scrolling, resizing, or mouse movement. By limiting the execution rate, throttling improves performance and prevents unnecessary workload on the browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What is Throttling<br>Throttling ensures that a function runs at a fixed interval regardless of how many times an event is triggered. Instead of executing the function every time the event occurs, it allows execution only once within a specified time limit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if a user scrolls rapidly, a throttled function will run at controlled intervals instead of running hundreds of times per second.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Why Use Throttling<br>Throttling helps reduce performance issues caused by frequent function calls<br>It improves user experience by ensuring smoother interactions<br>It prevents excessive API requests in web applications<br>It helps manage resource usage efficiently<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How Throttling Works<br>When a function is throttled, it checks the last time it was executed. If enough time has passed, it runs again. Otherwise, it skips execution until the defined delay is reached.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basic Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function throttle(func, limit) {<br>  let lastCall = 0;<br><br>  return function(...args) {<br>    const now = new Date().getTime();<br><br>    if (now - lastCall &gt;= limit) {<br>      lastCall = now;<br>      func.apply(this, args);<br>    }<br>  };<br>}<br><br>\/\/ Usage example<br>window.addEventListener(<br>  \"scroll\",<br>  throttle(() =&gt; {<br>    console.log(\"Scroll event handled\");<br>  }, 1000)<br>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Common Use Cases<br>Handling scroll events efficiently<br>Optimizing window resize operations<br>Limiting button click actions<br>Reducing repeated API calls<br>Improving animations and UI performance<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throttling vs Debouncing<br>Throttling executes a function at regular intervals during continuous events<br>Debouncing delays execution until the event has stopped firing<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When to Use Throttling<br>Use throttling when you need consistent updates at fixed intervals, such as tracking scroll position or updating animations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Best Practices<br>Choose an appropriate delay time based on user experience<br>Avoid very small delays that reduce effectiveness<br>Test performance impact on different devices<br>Combine with other optimization techniques if needed<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<br>Throttling is an important performance optimization technique in JavaScript. It helps control how frequently functions execute, making applications faster, smoother, and more efficient.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Professional JavaScript > Performance Optimization > Throttling<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1778085837886\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1778085837643\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-179","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Throttling - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=throttling\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Throttling - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=throttling\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-06T16:44:37+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=throttling\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=throttling\",\"name\":\"Throttling - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-06T16:44:35+00:00\",\"dateModified\":\"2026-05-06T16:44:37+00:00\",\"description\":\"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=throttling#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=throttling\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=throttling#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Professional JavaScript > Performance Optimization > Throttling\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Throttling - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=throttling","og_locale":"en_US","og_type":"article","og_title":"Throttling - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=throttling","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-06T16:44:37+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=throttling","url":"https:\/\/gigz.pk\/javascript\/?lesson=throttling","name":"Throttling - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-06T16:44:35+00:00","dateModified":"2026-05-06T16:44:37+00:00","description":"Learn JavaScript throttling to control function execution, improve performance, and optimize events like scroll and resize easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=throttling#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=throttling"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=throttling#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Professional JavaScript > Performance Optimization > Throttling"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}