diff --git a/2-ui/5-loading/02-script-async-defer/article.md b/2-ui/5-loading/02-script-async-defer/article.md index 24af956dc..afa2a8284 100644 --- a/2-ui/5-loading/02-script-async-defer/article.md +++ b/2-ui/5-loading/02-script-async-defer/article.md @@ -1,25 +1,25 @@ # Scripts: async, defer -In modern websites, scripts are often "heavier" than HTML: their download size is larger, and processing time is also longer. +মডার্ন ওয়েবসাইট গুলোতে আমাদের script সমূহের সাইজ HTML Document এর চেয়ে বড় হয়, ফলে এরা লোড হতে সময়ও বেশি নেয়। -When the browser loads HTML and comes across a `` tag, it can't continue building the DOM. It must execute the script right now. The same happens for external scripts ``: the browser must wait for the script to download, execute the downloaded script, and only then can it process the rest of the page. +একটি পেজ লোড হওয়ার সময় যখন `` ট্যাগ দেখে তখন এটি DOM বিল্ড থামিয়ে `` এর ক্ষেত্রে প্রথমে রিসোর্সটি ডাওনলোড করে এবং ডাওনলোড হওয়া পর্যন্ত এটি বাকী ডম পার্সিংকে ব্লক করে রাখে। -That leads to two important issues: +যার ফলে দুটি গুরত্বপূর্ণ ব্যাপার ঘটে: -1. Scripts can't see DOM elements below them, so they can't add handlers etc. -2. If there's a bulky script at the top of the page, it "blocks the page". Users can't see the page content till it downloads and runs: +1. script তার নিচের DOM কে পড়তে পারে না এবং হ্যান্ডেল করতে পারে না। +2. পেজের শুরুতে যদি কোন একটি বড় সাইজের script থাকে তাহলে এটি ডাওনলোড না হওয়া পর্যন্ত DOM পার্সিং ব্লক হয়ে থাকে: ```html run height=100
...content before script...
- +...content after script...
``` -There are some workarounds to that. For instance, we can put a script at the bottom of the page. Then it can see elements above it, and it doesn't block the page content from showing: +এক্ষেত্রে আমরা একটি কাজ করতে পারি, script কে পেজের একদম নিচে লোড করতে পারি। ফলে সম্পূর্ণ DOM পার্স হয় এবং এটি কোন কন্টেন্টকে ব্লক করে না: ```html @@ -29,33 +29,33 @@ There are some workarounds to that. For instance, we can put a script at the bot ``` -But this solution is far from perfect. For example, the browser notices the script (and can start downloading it) only after it downloaded the full HTML document. For long HTML documents, that may be a noticeable delay. +এভাবে আমরা আমাদের সমস্যাটি সমাধান করতে পারি। ব্রাউজার সম্পূর্ণ HTML ডকুমেন্ট পার্স করে script কে পার্স করে। তবে দীর্ঘ HTML ডকুমেন্টের জন্য কিছুটা সময় লাগতে পারে। -Such things are invisible for people using very fast connections, but many people in the world still have slow internet speeds and use a far-from-perfect mobile internet connection. +দ্রুত গতির ইন্টারনেট কানেকশনের জন্য এই সমস্যাটি প্রায় অদৃশ্যই থেকে যায়, তবে আমাদের পৃথিবীতে এখনো ইন্টারনেট সহজলভ্য না হওয়ায় অনেকেই স্বল্প গতির ইন্টারনেট যেমন মোবাইল ইন্টারনেট কানেকশন ব্যবহার করে। -Luckily, there are two ` - +...content after script...
``` -In other words: +সুতরাং বলা যায়: -- Scripts with `defer` never block the page. -- Scripts with `defer` always execute when the DOM is ready (but before `DOMContentLoaded` event). +- Scripts এ `defer` ব্যবহার করা হলে তা পেজকে ব্লক করে রাখে না। +- Scripts এ `defer` ব্যবহার করা হলে তা এক্সিকিউট হবে DOM রেডি হওয়ার পর (তবে `DOMContentLoaded` ইভেন্ট ট্রিগার হবে Scripts এক্সিকিউট হওয়ার পর)। -The following example demonstrates the second part: +এখানে `DOMContentLoaded` ইভেন্ট ট্রিগার হওয়ার একটি উদাহরণ দেখুন: ```html run height=100...content before scripts...
@@ -69,45 +69,45 @@ The following example demonstrates the second part:...content after scripts...
``` -1. The page content shows up immediately. -2. `DOMContentLoaded` event handler waits for the deferred script. It only triggers when the script is downloaded and executed. +1. HTML কন্টেন্ট সমূহকে শুরুতে দেখাবে। +2. `DOMContentLoaded` ইভেন্ট deferred script সমূহ ডাওনলোড হয়ে এক্সিকিউট হওয়ার পর ট্রিগার হবে। -**Deferred scripts keep their relative order, just like regular scripts.** +**Deferred scripts সমূহ রেগুলার scripts এর মত DOM এর ক্রম অনুসারে এক্সিকিউট হয়** -Let's say, we have two deferred scripts: the `long.js` and then `small.js`: +মনে করুন, আমাদের দুটি deferred scripts আছে: `long.js` এবং `small.js`: ```html ``` -Browsers scan the page for scripts and download them in parallel, to improve performance. So in the example above both scripts download in parallel. The `small.js` probably finishes first. +পারফরম্যান্সের জন্য ব্রাউজার দুটি স্ক্রিপ্টস সমান্তরালে ডাওনলোড করবে। উপরের উদাহরণে দুটি স্ক্রিপ্টস সমান্তরালে ডাওনলোড হবে এবং সম্ভবত `small.js` এ প্রথমে ডাওনলোড সম্পন্ন করবে, যেহেতু এটির সাইজ কম। -...But the `defer` atribute, besides telling the browser "not to block", ensures that the relative order is kept. So even though `small.js` loads first, it still waits and runs after `long.js` executes. +...তবে `defer` অ্যাট্রিবিউট DOM পার্সিং ব্লক না করার পাশাপাশি আরো একটি ব্যাপার নিশ্চিত করে তা হল এরা ক্রম অনুসারে এক্সিকিউট হয়। এখানে যদিও `small.js` প্রথমে ডাওনলোড হবে তারপরও এটি এক্সিকিউট হবে `long.js` ডাওনলোড হয়ে এক্সিকিউট হওয়ার পর। -That may be important for cases when we need to load a JavaScript library and then a script that depends on it. +যখন আমরা কোন একটি জাভাস্ক্রিপ্ট লাইব্রেরী ব্যবহার করি এবং তার উপর অন্য একটি স্ক্রিপ্টস নির্ভর করে তখন এই ব্যাপারটি আমাদের মনে রাখতে হবে। -```smart header="The `defer` attribute is only for external scripts" -The `defer` attribute is ignored if the `