मॉडर्न वेब गाइडेंस 101

1. मॉडर्न वेब गाइडेंस क्या है?

मॉडर्न वेब गाइडेंस, कोडिंग एजेंट पर सीधे तौर पर, मॉडर्न वेब डेवलपमेंट के सबसे सही तरीके और ब्राउज़र की सुसंगतता लागू करता है. इन तरीकों से यह पक्का होता है कि आपका कोड, वेब प्लैटफ़ॉर्म की मौजूदा क्षमताओं के मुताबिक हो. मॉडर्न वेब गाइडेंस, नए प्रोटोटाइप डेवलप करने से लेकर लेगसी सिस्टम को रिफ़ैक्टर करने तक, मॉडर्न वेब स्टैंडर्ड का ऐक्सेस देता है.

डेवलपर इसका इस्तेमाल इन कामों के लिए कर सकते हैं:

  • मज़बूत आधार पर बनाना: ऐसे प्रोजेक्ट शुरू करना जिनमें इंटरऑपरेबल वेब सुविधाओं का इस्तेमाल किया जाता है.
  • लेगसी कोड को मॉडर्न बनाना: सामान्य यूज़र इंटरफ़ेस पैटर्न के लिए, खास तौर पर बनाए गए कोड को बदलना.
  • डेवलप करते समय सीखना: मॉडर्न वेब पैटर्न के बारे में अपनी जानकारी बेहतर बनाना, क्योंकि यह सुविधा डेवलपमेंट के दौरान, कॉन्टेक्स्ट के हिसाब से गाइडेंस देती है.

लेगसी ऐप्लिकेशन की ऑडिटिंग करके, बेसलाइन टारगेट सेट करके, और मॉडर्न वेब गाइडेंस के नियमों के हिसाब से, स्टैंडर्ड एआई के सुझावों की तुलना करके, आपको मॉडर्न-वेब-गाइडेंस की बेहतर सुविधा वाले कोडिंग एजेंट को प्रॉम्प्ट करने का तरीका पता चलता है. इससे, पुराने या सामान्य मॉडल के आउटपुट पर निर्भर रहने के बजाय, हाई-परफ़ॉर्मेंस वाला मॉडर्न वेब कोड जनरेट किया जा सकता है.

2. ज़रूरी शर्तें

इस कोडलैब को शुरू करने से पहले, पक्का करें कि आपको इन चीज़ों के बारे में जानकारी हो:

इस कोडलैब में इनका इस्तेमाल किया गया है:

यह कोडलैब, लेगसी "Cozy Nook" ऐप्लिकेशन से शुरू होता है. इसे जान-बूझकर लेगसी कोड से बनाया गया है. डेमो रिपॉज़िटरी क्लोन करें और cozy-nook-bookshop वेब ऐप्लिकेशन पर जाएं.

git clone git@github.com:GoogleChromeLabs.modern-web-guidance-demos.git
cd modern-web-guidance-demos/legacy-demos/cozy-nook-bookshop/

3. अपना बेसलाइन टारगेट सेट करना

बेसलाइन से यह जानकारी मिलती है कि आज के समय में, ब्राउज़र में कौनसी सुविधाएं इंटरऑपरेबल हैं. इससे यह भी तय किया जा सकता है कि आपको किन ब्राउज़र के लिए सहायता देनी है. इसके लिए, आपको ब्राउज़र इंजन और वर्शन तय करने की ज़रूरत नहीं होती. किसी सुविधा को बेसलाइन तब माना जाता है, जब वह इंटरऑपरेबल हो.

अपना वेब ऐप्लिकेशन डेवलप करने से पहले, अपना बेसलाइन टारगेट चुनें. डिफ़ॉल्ट रूप से, modern-web-guidance, बेसलाइन की 'व्यापक तौर पर उपलब्ध' सुविधा का इस्तेमाल करता है. इसमें वे सुविधाएं शामिल होती हैं जो कम से कम 30 महीनों से इंटरऑपरेबल हैं. अगर आपको नई सुविधाओं के लिए सहायता देनी है, तो आपको अपनी AGENTS.md फ़ाइल में, सही बेसलाइन टारगेट शामिल करना होगा.

इस कोडलैब के लिए, इस प्रोजेक्ट में baseline widely available on 2026-06-01 का फ़िक्स टारगेट इस्तेमाल किया गया है.

// AGENTS.md
This project's Baseline target is "Baseline widely available on 2026-06-01".

4. प्रोजेक्ट की अहम ज़रूरतें तय करना

बेसलाइन टारगेट चुनने के बाद, अहम ज़रूरतें तय करें. साथ ही, उनसे जुड़ी सुविधाओं और विषयों को बैच करें. धीरे-धीरे सुधार करने के मेंटल मॉडल को अपनाएं. जैसे, किसी सुविधा को बनाते समय अपनाया जाता है.

अपनी अपडेट को, पुरानी हो चुकी खास सुविधाओं या वेब डेवलपमेंट के बड़े विषयों के हिसाब से कैटगरी में बांटें. उदाहरण के लिए:

  • परफ़ॉर्मेंस: अपने Core Web Vitals को ऑप्टिमाइज़ करें.
  • उपयोगकर्ता अनुभव: इंटरैक्शन और इस्तेमाल में आसानी को बेहतर बनाना.
  • सुलभता: सुलभता से जुड़ी समस्याओं को हल करना, ताकि आपके ऐप्लिकेशन को ज़्यादा लोग ऐक्सेस कर सकें.
  • फ़ॉर्म और सुरक्षा: इनपुट हैंडलिंग को मॉडर्न बनाना और अपने ऐप्लिकेशन के डेटा एंट्री पॉइंट को सुरक्षित करना.

इस कोडलैब में, आपका फ़ोकस लेगसी बुकशॉप ऐप्लिकेशन की परफ़ॉर्मेंस की तुलना करने पर होगा. इससे यह पता चलेगा कि मॉडर्न वेब गाइडेंस की सुविधा, इसकी स्पीड को कैसे बेहतर बनाती है. एक बार में एक टास्क पर फ़ोकस करें, ताकि एजेंट के किए गए बदलावों की निगरानी की जा सके. साथ ही, यह पक्का किया जा सके कि नतीजा, आपके प्रोजेक्ट के लक्ष्यों के मुताबिक हो.

शुरू करने के लिए, Lighthouse ऑडिट का इस्तेमाल करके, यह साफ़ तौर पर जानें कि बुकशॉप ऐप्लिकेशन अपनी शुरुआती स्थिति में कैसा परफ़ॉर्म करता है.

अपनी लोकल मशीन पर Antigravity CLI खोलें और नया सेशन शुरू करें:

agy

आपको एजेंट का आउटपुट, इस तरह दिखना चाहिए.

 Bash(ctrl+o to expand)
 Thought for 13s
 This report will detail the desktop and mobile scores, provide a comparative metrics table, explain the root causes of the performance bottlenecks, and offer highly actionable recommendations based on modern web standards (e.g. Baseline Widely available on 2026-06-01 target).


 Create(lighthouse_audit_report.md) (ctrl+o to expand)
 Thought for 5s
  Confirming Task Completion
  I have successfully run the Lighthouse audits using  npx lighthouse  for both desktop and mobile viewports against a production build of the application.


The generated local reports have been saved in the project root:
 Mobile Reports: lighthouse-mobile.report.html and lighthouse-mobile.report.json
 Desktop Reports: lighthouse-desktop.report.html and lighthouse-desktop.report.json

I have compiled the audit scores, identified performance bottlenecks, and outlined a step-by-step key improvement action plan in the following artifact:

Open lighthouse_audit_report.md

मार्कडाउन खोलने पर, हमें ये नतीजे मिलते हैं:

Here is the complete Lighthouse audit report generated for the application:

**Lighthouse Audit Report: Cozy Nook Bookshop**

This report provides the Lighthouse audit scores, core web vitals performance
metrics, and key areas for improvement for The Legacy Cozy Nook in development mode.

**Summary Scores**

| Category        | Mobile Score | Desktop Score |
|-----------------|--------------|---------------|
| Performance     | 61 / 100    | 93 / 100 |
| Accessibility   | 98 / 100  | 98 / 100 |
| Best Practices   | 96 / 100  | 96 / 100 |
| SEO       | 92 / 100  | 92 / 100 |

** Core Web Vitals & Key Metrics**

| Metric        | Mobile Value | Desktop Value |
|-----------------|--------------|---------------|
| First Contentful Paint (FCP)     | 2.9 s    | 0.7 s |
| Largest Contentful Paint (LCP)   | 4.8 s  | 1.2 s |
| Total Blocking Time (TBT)  | 0 ms | 0 ms |
| Cumulative Layout Shift (CLS)      | 0.336  | 0.114 |
| Speed Index (SI)      | 2.9 s  | 0.7 s |

मोबाइल पर परफ़ॉर्मेंस के लिए, ऐप्लिकेशन को 100 में से 61 स्कोर मिला है. ऐप्लिकेशन को मोबाइल के लिए ऑप्टिमाइज़ करने और परफ़ॉर्मेंस स्कोर को बेहतर बनाने के सुझाव पाने के लिए, modern-web-guidance से क्वेरी करें.

5. परफ़ॉर्मेंस बेहतर बनाने के लिए क्वेरी करना

स्टैंडर्ड बेस मॉडल से जनरेट किए गए सुझावों और modern-web-guidance के चालू होने पर जनरेट किए गए सुझावों के बीच के अंतर का आकलन करने के लिए, तुलना टेस्ट करें. इसके लिए, एजेंट से परफ़ॉर्मेंस ऑप्टिमाइज़ेशन के सुझावों के लिए पूछें.

सबसे पहले, modern-web-guidance इंस्टॉल किए बिना, बेस मॉडल से क्वेरी करें. इससे यह पता चलेगा कि यह मोबाइल वेब की परफ़ॉर्मेंस को बेहतर बनाने के लिए किस तरह के सुझाव दे सकता है.

वेब सुविधाओं का आउटपुट देखने के बाद, जिसमें यह बताया गया हो कि मॉडल ने इसकी सलाह क्यों दी, किसी दूसरी टर्मिनल विंडो में modern-web-guidance इंस्टॉल करें और सभी डिफ़ॉल्ट सेटिंग स्वीकार करें.

npx modern-web-guidance@latest install

Antigravity पर वापस जाएं, नई इंस्टॉल की गई सुविधा से क्वेरी करें, और उससे बेस मॉडल के सुझाए गए सुझावों की सूची से तुलना करने के लिए कहें.

 Bash(npx -y modern-web-guidance@latest search "performance")
    [{"id":"performance","description":"Actionable guidelines for optimizing modern web applications. Use this guide when auditing performance, optimizing loading metrics, fixing slow interactions and optimizing Core Web Vitals (LCP, INP, CLS)","category":"performance","similarity":0.5569},
            {"id":"efficient-background-processing","description":"Conserve system resources and battery life by pausing background JavaScript execution (such as `<canvas>` animations, WebGL rendering, or high-frequency WebSocket data polling) when the component is off-screen and then resume them just-in-time when they scroll back into view.","category":"performance","featuresUsed":["content-visibility"], "similarity":0.5066},
            {"id":"html","description":"Action-oriented guidelines for modern HTML architecture, semantics, native interactive APIs (Dialog, Popover, Details), focus management, and resource prioritization. Use this
            guide when structuring web documents, implementing native overlays, or optimizing resource loading order.","category":"html", "similarity":0.4478},
            {"id":"faster-spa-view-transitions","description":"Enable faster transitions back to previously visited views in a Single-Page Application (SPA) by preserving their structural DOM state instead of
            destroying and rebuilding them on every navigation.","category":"performance","featuresUsed":["content-visibility"], "similarity":0.444},
            {"id":"identify-heavy-scripts","description":"Identify the scripts most responsible for long animation frames","category":"performance","featuresUsed":["Long animation
            frames"], "similarity":0.4287}] (ctrl+o to collapse)


 Bash(npx -y modern-web-guidance@latest search "image")
    [{"id":"deliver-optimized-decorative-images","description":"Deliver optimized decorative images (such as backgrounds, UI icons, or complex masks) by simultaneously providing next-generation image formats
            (like AVIF or WebP) alongside multiple pixel densities (like 1x and 2x) so the browser can dynamically negotiate the best combination of file size and visual quality for the user's device
            capabilities.","category":"user-experience","featuresUsed":["image-set()"], "similarity":0.4038},
            {"id":"performance","description":"Actionable guidelines for optimizing modern web applications. Use this guide when auditing performance, optimizing loading metrics, fixing slow interactions and
            optimizing Core Web Vitals (LCP, INP, CLS)","category":"performance", "similarity":0.3761},
            {"id":"visually-texture-content","description":"Apply realistic weathering and texture patterns to elements to give them an organic, aged, or physical material
            appearance.","category":"user-experience","featuresUsed":["Masks"], "similarity":0.3716},
            {"id":"resolution-optimized-pseudo-elements","description":"Use resolution-optimized images in CSS pseudo-elements (such as `::before` and `::after`) to reduce the number of DOM
            nodes.","category":"performance","featuresUsed":["image-set()"], "similarity":0.3566},
            {"id":"optimize-image-priority","description":"Optimize the loading priority of Largest Contentful Paint (LCP) candidate images and deprioritize non-critical images to reduce critical resource load
            delays.","category":"performance","featuresUsed":["Fetch priority"],"similarity":0.32}] (ctrl+o to collapse)

 Bash(npx -y modern-web-guidance@latest retrieve "performance,optimize-image-priority")
    <output +165 lines>
            - **RECOMMENDED**: Avoid using `fetchpriority="auto"`. If you want the default priority, omit the attribute entirely to keep your HTML clean.
            - **DO NOT** combine `fetchpriority="high"` with `loading="lazy"` for the LCP image.
            - **DO NOT** use the deprecated `importance` attribute. It has been replaced by `fetchpriority` and is not supported by any browser.
            ## Fallback strategy
            Baseline status for Fetch priority: Newly available. It's been Baseline since 2024-10-29.
            Supported by: Chrome 103 (Jun 2022), Edge 103 (Jun 2022), Firefox 132 (Oct 2024), and Safari 17.2 (Dec 2023).
            The `fetchpriority` attribute is a progressive enhancement for the `<img>` element. If a browser does not support it, the attribute is ignored, and the browser uses its default priority heuristics. (ctrl+o
     to collapse)  

एजेंट के गहराई से विश्लेषण पूरा करने के बाद, यह एक तुलनात्मक विश्लेषण दिखाता है. इसमें, modern-web-guidance स्किल के साथ और उसके बिना, मॉडल के सुझाव दिखाए जाते हैं. साथ ही, एक जैसे सुझावों को हाइलाइट किया जाता है. यह आउटपुट, Gemini मॉडल के वर्शन और modern-web-guidance के मौजूदा वर्शन पर निर्भर करता है.

लोकल एनवायरमेंट अलग-अलग हो सकते हैं. इसलिए, GitHub रिपॉज़िटरी में कोई समस्या दर्ज करके, मॉडर्न वेब गाइडेंस के बारे में अपने नतीजों और सुझावों को शेयर करें.

एजेंट का आउटपुट, इस तरह दिखना चाहिए:

 ### 1. Base Model Knowledge Recommendations (Internal Training Only)
  Based purely on standard web development practices, the following steps are recommended to improve the application's mobile performance score:

  • Hero Image Optimization: Move the dynamic Javascript-loaded hero image into the source HTML file ( index.html ) so the browser preload scanner can fetch it immediately. Add  fetchpriority="high"  and serve the image in modern WebP
  or AVIF formats.

  • Layout Stability (CLS): Provide explicit  width  and  height  dimensions in HTML image elements so the browser can calculate the layout box size before the image has finished loading.
  • Payload Compression: Minify JS and CSS bundles and compress images to reduce the 6.1 MB payload.
  • Resource Optimization: Defer non-critical scripts and lazy-load offscreen/below-the-fold images.


  ──────


  ### 2. Fetched Modern Web Guidance Guides
  The following official performance guides were successfully fetched and inspected from the repository's local skills folder:

  1.  optimize-image-priority.md
  2.  improve-next-page-load-performance.md
  3.  performance.md
  ──────

  ### 3. Comparison & Key Constraints Comparison
  Below is the side-by-side comparison of the base model recommendations against the fetched performance guidelines:

    | Optimization Area | Base Model Recommendation | Modern Web Guidance Rule | Mandatory Constraints & Discrepancies |
|---|---|---|---|
| Lazy Loading & Fetch Priority Interaction | Standard separation of lazy-load and high priority. | MANDATORY: Do not combine fetchpriority="high" with loading="lazy" on LCP images, and do not use fetchpriority="low" on standard below-the-fold lazy-loaded images. | Constraint: Below-the-fold lazy-loaded images must load at normal priority when they enter the viewport; low priority is reserved strictly for hidden above-the-fold content. |
| Speculative Loading | Preload the next page elements or assets generally. | DO: Use the Speculation Rules API (JSON-based script) to prefetch or prerender pages the user will likely visit next. | Discrepancy: The base model recommends traditional asset preloads. The guide introduces modern speculation rules (list and document rules). |
| Speculative Loading Restrictions | Standard speculative prefetching. | DO NOT use speculation rules on Single Page Applications (SPAs). DO NOT speculate URLs that trigger state changes (e.g., /logout , /add-to-cart ). | Constraint: Explicitly blocks speculation rules for SPA routers and state-changing actions to prevent unintentional sessions/actions from being triggered by background browser requests. |
| Main Thread & INP | Break up long tasks and throttle events. | DO: Implement the 50ms rule: any script execution > 50ms must yield to the main thread. Use scheduler.yield() with a Promise fallback. | Constraint: Explicitly forbids relying only on setTimeout(..., 0) because it places continuations at the back of the queue, potentially starving user input. |
| CSS Content Visibility | Standard style minification. | DO: Pair content-visibility: auto with contain-intrinsic-size for offscreen elements on large, complex pages only. | Constraint: Forbids using content-visibility: auto on simple/small pages or above-the-fold content due to overhead and jumping risks. |

तुलना को ज़्यादा बारीकी से देखने के लिए, यह टेबल देखें:

ऑप्टिमाइज़ेशन का इलाका

बेस मॉडल का सुझाव

मॉडर्न वेब गाइडेंस का नियम

अनिवार्य पाबंदियां और अंतर

लेज़ी लोडिंग और फ़ेच प्राथमिकता इंटरैक्शन

लेज़ी-लोड और ज़्यादा प्राथमिकता को अलग-अलग रखना.

अनिवार्य: एलसीपी इमेज पर fetchpriority="high" को loading="lazy" के साथ न मिलाएं. साथ ही, फ़ोल्ड के नीचे मौजूद, सामान्य लेज़ी-लोड की गई इमेज पर fetchpriority="low" का इस्तेमाल न करें.

पाबंदी: फ़ोल्ड के नीचे मौजूद, लेज़ी-लोड की गई इमेज, व्यूपोर्ट में आने पर सामान्य प्राथमिकता पर लोड होनी चाहिए. कम प्राथमिकता, फ़ोल्ड के ऊपर मौजूद छिपे हुए कॉन्टेंट के लिए रिज़र्व होती है.

अनुमान के हिसाब से यूआरएल लोड होने की सुविधा

आम तौर पर, अगले पेज के एलिमेंट या ऐसेट को पहले से लोड करें.

ज़रूरी: Speculation Rules API (JSON-आधारित स्क्रिप्ट) का इस्तेमाल करके, उन पेजों को प्रीफ़ेच या प्रीरेंडर करें जिन पर आपके अगले पेज पर जाने की संभावना है.

अंतर: बेस मॉडल, ऐसेट को पहले से लोड करने के बुनियादी सुझाव देता है. गाइड में, अनुमान लगाने के मॉडर्न नियमों (सूची और दस्तावेज़ के नियम) के बारे में बताया गया है.

अनुमान के हिसाब से यूआरएल लोड होने की सुविधा पर पाबंदियां

अनुमान के हिसाब से, पहले से फ़ेच करने की सामान्य सुविधा.

सिंगल-पेज ऐप्लिकेशन (एसपीए) पर, अनुमान लगाने के नियमों का इस्तेमाल न करें. ऐसे यूआरएल का अनुमान न लगाएं जिनसे स्टेट में बदलाव होता है. जैसे, /logout या /add-to-cart.

पाबंदी: एसपीए राऊटर और स्टेट में बदलाव करने वाली कार्रवाइयों के लिए, अनुमान लगाने के नियमों को साफ़ तौर पर ब्लॉक करता है, ताकि बैकग्राउंड में ब्राउज़र के अनुरोधों से, अनचाहे सेशन या कार्रवाइयां ट्रिगर न हों.

मुख्य थ्रेड और आईएनपी

लंबे टास्क को छोटे-छोटे हिस्सों में बांटें और इवेंट को थ्रॉटल करें.

ज़रूरी: 50 मि॰से॰ का नियम लागू करें: 50 मि॰से॰ से ज़्यादा समय तक चलने वाली किसी भी स्क्रिप्ट को मुख्य थ्रेड पर चलना चाहिए. प्रॉमिस फ़ॉलबैक के साथ scheduler.yield() का इस्तेमाल करें.

पाबंदी: सिर्फ़ setTimeout(..., 0) पर निर्भर रहने की अनुमति नहीं है, क्योंकि इससे कंटीन्यूएशन को क्यू के आखिर में रखा जाता है. इससे, उपयोगकर्ता के इनपुट को प्रोसेस करने में समस्या आ सकती है.

सीएसएस कॉन्टेंट की विज़िबिलिटी

स्टाइल को छोटा करने की सामान्य सुविधा.

ज़रूरी: सिर्फ़ बड़े और मुश्किल पेजों पर, ऑफ़स्क्रीन एलिमेंट के लिए content-visibility: auto को contain-intrinsic-size के साथ जोड़ें.

पाबंदी: ओवरहेड और जंपिंग के जोखिम की वजह से, आसान पेजों या फ़ोल्ड के ऊपर मौजूद कॉन्टेंट पर content-visibility: auto का इस्तेमाल करने की अनुमति नहीं है.

टेबल से पता चलता है कि बेस मॉडल को यह पता है कि परफ़ॉर्मेंस को कैसे बेहतर बनाया जाए. हालांकि, modern-web-guidance उन सामान्य सुझावों को सख्त नियमों में बदल देता है.

"लेज़ी लोडिंग और फ़ेच प्राथमिकता इंटरैक्शन" सेक्शन में, बेस मॉडल यह पहचानता है कि loading="lazy" एक अच्छा तरीका है. हालांकि, यह सुविधा अहम जानकारी देती है: fetchpriority="low" को कभी भी loading="lazy" एट्रिब्यूट के साथ न मिलाएं. एआई एजेंट के साथ कोडिंग करते समय, यह नियम लागू करना काम का होता है.

एजेंट को modern-web-guidance के सख्त नियमों के बारे में बताने के बाद, एजेंट से दोनों तरीकों के लिए कोड का ड्राफ़्ट तैयार करने के लिए कहें, ताकि लागू करने के तरीके में अंतर देखा जा सके.

एजेंट के सुझाए गए प्लान की समीक्षा करें:

 Thought for 2s
  Formulating Mobile Optimization Plans

  Okay, I'm currently focused on crafting two mobile optimization plans as
  requested. I'm structuring them specifically for both a base model and one
  leveraging modern-web-guidance. I'm adding sources and baselines to each for
  comparison. My goal is to present these plans to you for review before any
  implementation begins. I'm trying to make sure I get this exactly right.
...
 ListDir(modern-web-guidance-demos/legacy-demos/cozy-nook-bookshop/static/assets)
    8 files, 0 directories (ctrl+o to collapse)
  Below are two implementation plans to optimize the mobile performance of The
  Cozy Nook to a 90+ score.
  ──────
  ### Plan A: Base Model Only (Traditional Web Performance)

  This plan uses classic web performance optimization patterns based on general
  knowledge from standard MDN/web.dev documentation.

  #### Proposed Changes
  1.  LCP Hero Image HTML Declaration:
       Modify index.html to include the static hero image source directly:
        <img src="./assets/hero-img.png" alt="Old Books stack on wooden table" class="hero-img">
       Remove the dynamic JS source injection in hero.js to prevent JS execution delay blocking the render.
  2.  Critical Preload Link:
       Add a preload link in the <head> of index.html to prioritize the asset request:
        <link rel="preload" as="image" href="./assets/hero-img.png">
  3.  Cumulative Layout Shift (CLS) Fixes:
       Add explicit width and height dimensions to all static image elements in index.html (e.g., hero, staff picks, avatars).

  #### Sources & References
   Preloading Assets: MDN Web Docs - Preloading Content https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload
   CLS Prevention: web.dev - Optimize Cumulative Layout Shift https://web.dev/articles/cls
### Plan B: Modern Web Guidance (Recommended)

  This plan strictly follows Google Chrome's modern guidelines, progressive
  enhancements, and rules. It minimizes resource contention and leverages native
  speculation tools.

  #### Proposed Changes

  1.  HTML Declaration with Native Fetch Priority:
      • Modify index.html to load the hero image inline and declare priority:
        <img src="./assets/hero-img.png" fetchpriority="high" alt="Old Books stack on wooden table" class="hero-img">

      • Constraint Met: Do not add a duplicate <link rel="preload">. Modern web
        guidance mandates letting the browser's preload scanner natively discover
        the raw HTML image tag. Adding a separate preload resource block causes
        unnecessary network overhead.
       Remove the dynamic source loading in hero.js.
  2.  Explicit Layout Boundaries (CLS):
       Set physical width and height attributes matching the design aspect
        ratio directly on the hero, pick covers, and avatar elements inside
        index.html.
  3.  Speculative MPA Navigation (Next-page optimization):
       Since this is a Multi-Page Application (MPA), embed a Speculation Rules
        script block in the bottom of index.html to prefetch same-origin routes
        (about.html, contact.html, details.html) with moderate eagerness with
        script type "speculationrules" with the following content.
          {
            "prefetch": [{
              "where": {
                "and": [
                  { "href_matches": "/*" },
                  { "not": { "href_matches": "/basket.html" } }
                ]
              },
              "eagerness": "moderate"
            }]
          }

       Constraint Met: We explicitly exclude shopping checkout items like
        basket.html from prefetching to avoid unnecessary/accidental request
        triggers.

  #### Sources & References

   optimize-image-priority.md
   improve-next-page-load-performance.md
   performance.md

6. बिना गाइडेंस के लागू करने के तरीके की तुलना, गाइडेंस के साथ लागू करने के तरीके से करना

यहां, इस बुकशॉप ऐप्लिकेशन के लिए, Gemini और modern-web-guidance के साथ तुलना टेस्ट के एजेंट के सैंपल आउटपुट दिए गए हैं.

हो सकता है कि आपको अलग-अलग नतीजे दिखें. इसलिए, तय चरणों के बजाय इस रणनीति का इस्तेमाल करें. इन प्लान का इस्तेमाल करके देखें कि आपके कंप्यूटर पर बुकशॉप ऐप्लिकेशन के लिए modern-web-guidance चालू करने पर, चीज़ें कैसे बदलती हैं. तुलना टेस्ट पूरे करने के बाद, अपने एजेंट से पूछें कि आपके खास सेटअप के लिए कौनसा तरीका सबसे अच्छा काम करता है.

अपडेट करने के दौरान, असल में होने वाले सुधारों को देखने के लिए, Lighthouse या DevTools for Agents की मदद से अपने ऐप्लिकेशन की परफ़ॉर्मेंस को ट्रैक किया जा सकता है.

1. लेज़ी लोडिंग और फ़ेच प्राथमिकता इंटरैक्शन

ऑफ़स्क्रीन इमेज को ऑप्टिमाइज़ करें, ताकि मुख्य थ्रेड के बैंडविथ में होने वाली समस्या से बचा जा सके.

प्लान A (बेस मॉडल)

सभी ऑफ़स्क्रीन इमेज पर, स्टैंडर्ड loading="lazy" लागू करें. (बेहतर नहीं: ऑफ़स्क्रीन ऐसेट को लेज़ी-लोड करें. हालांकि, एलसीपी इमेज के अलावा, फ़ोल्ड के ऊपर मौजूद दिखने वाली ऐसेट को एलसीपी इमेज के साथ कंपीट करने दें.)

<img src="https://..." alt="..." class="pick-small-img" loading="lazy">

प्लान B (मॉडर्न वेब गाइडेंस)

fetchpriority="low" के साथ, फ़ोल्ड के ऊपर मौजूद उन एलिमेंट को टारगेट करें जो शुरू में नहीं दिखते. साथ ही, पक्का करें कि लेज़ी-लोड की गई स्टैंडर्ड इमेज, डिफ़ॉल्ट प्राथमिकताओं पर बनी रहें. (सबसे अच्छा विकल्प: छिपी हुई ऐसेट को डिमोट करें. इससे, क्रिटिकल रेंडरिंग पाथ ब्लॉक नहीं होता. साथ ही, स्क्रोल-इन लोड टाइम भी कम नहीं होता.)

<img src="https://..." fetchpriority="low" width="96" height="144" alt="..." class="pick-small-img" loading="lazy">

2. अनुमान के हिसाब से यूआरएल लोड होने की सुविधा

अगले पेज के दस्तावेज़ या ऐसेट को पहले से फ़ेच करके, आने वाले समय में पेज लोड होने की स्पीड बढ़ाएं.

प्लान A (बेस मॉडल)

इस तरीके में, एलिमेंट का इस्तेमाल किया जाता है. (बेहतर नहीं: सबपेज ट्रांज़िशन में अब भी करीब एक सेकंड की देरी होती है.)

<link rel="prefetch" href="about.html">
<link rel="prefetch" href="contact.html">

प्लान B (मॉडर्न वेब गाइडेंस)

Speculation Rules API का इस्तेमाल करता है. (सबसे अच्छा विकल्प: Speculation Rules की मदद से, मैचिंग क्वेरी के साथ, प्रीफ़ेच करने और प्रीरेंडरिंग की सुविधा का इस्तेमाल किया जा सकता है. इससे, नेविगेशन में लगने वाले समय को कम किया जा सकता है.)

<script type="speculationrules">
  {
    "prefetch": [{
      "where": { "href_matches": "/*" },
      "eagerness": "moderate"
    }]
  }
</script>

3. अनुमान के हिसाब से यूआरएल लोड होने की सुविधा पर पाबंदियां

सुरक्षा, परफ़ॉर्मेंस या स्टेट से जुड़ी समस्याओं को रोकने के लिए, कुछ पेजों को पहले से फ़ेच करने से साफ़ तौर पर ब्लॉक करें. उदाहरण के लिए, /logout या /basket.html.

प्लान A (बेस मॉडल)

इस तरीके के लिए, डेवलपर को मैन्युअल तरीके से मैनेज करना होता है कि किन यूआरएल को शामिल करना है. (बेहतर नहीं: यह तरीका जोखिम भरा है, क्योंकि इससे बैकग्राउंड में अनचाही कार्रवाइयों का सुरक्षा जोखिम बढ़ जाता है.)

प्लान B (मॉडर्न वेब गाइडेंस)

इस तरीके में, एडमिन, स्टेटफ़ुल या शॉपिंग पाथ को साफ़ तौर पर शामिल नहीं किया जाता. (सबसे अच्छा विकल्प: प्रोग्राम के हिसाब से एक्सक्लूज़न, ब्राउज़र को बैकग्राउंड में अनचाही कार्रवाइयां करने से रोकते हैं.)

<script type="speculationrules">
  {
    "prefetch": [{
      "where": {
        "and": [
          { "href_matches": "/*" },
          { "not": { "href_matches": "/wp-admin/*" } },
          { "not": { "href_matches": "/basket.html" } },
          { "not": { "selector_matches": ".do-not-prerender" } }
        ]
      },
      "eagerness": "moderate"
    }]
  }
</script>

4. मुख्य थ्रेड और पेज के रिस्पॉन्स में लगने वाला समय (आईएनपी)

उपयोगकर्ता के इनपुट के लिए, मुख्य थ्रेड की उपलब्धता को प्राथमिकता दें, ताकि रिस्पॉन्सिवनेस को बनाए रखा जा सके.

प्लान A (बेस मॉडल):

सिंक्रोनस कॉलबैक लूप का इस्तेमाल करके, मुश्किल कैलकुलेशन को बाद के लिए टालें. (बेहतर नहीं: अगर पेज पर मुख्य थ्रेड व्यस्त है, तो आपको पेज के रिस्पॉन्स में लगने वाला समय (आईएनपी) ज़्यादा हो सकता है.)

function renderBigCatalog(items) {
  items.forEach(item => {
    renderItem(item);
  });
}

प्लान B (मॉडर्न वेब गाइडेंस):

मुख्य थ्रेड को रिस्पॉन्सिव बनाए रखने के लिए, scheduler.yield() का इस्तेमाल करके, मुख्य थ्रेड पर चलें. (सबसे अच्छा विकल्प: scheduler.yield() तरीका, टास्क स्टार्वेशन के बिना इनपुट को रिस्पॉन्सिव बनाए रखने में मदद करता है.)

async function yieldToMain() {
  if ('scheduler' in window && 'yield' in scheduler) {
    return await scheduler.yield();
  }

  return new Promise(resolve => setTimeout(resolve, 0));
}

async function renderBigCatalog(items) {
  for (let i = 0; i < items.length; i++) {
    renderItem(items[i]);

    if (i % 50 === 0) {
      await yieldToMain();
    }
  }
}

5. सीएसएस content-visibility

ऑफ़स्क्रीन एलिमेंट के रेंडरिंग ऑपरेशन को बाद के लिए टालकर, ऑफ़स्क्रीन लेआउट कैलकुलेशन मैनेज करें.

प्लान A (बेस मॉडल)

स्टाइलशीट बंडल को छोटा करें. (बेहतर नहीं: शुरुआती पेंट पर, रेंडरिंग का सामान्य ओवरहेड.)

.book-item {
  display: flex;
  margin: 1rem;
}

प्लान B (मॉडर्न वेब गाइडेंस)

ऑफ़स्क्रीन एलिमेंट को तब तक पेंट न करें, जब तक वे व्यूपोर्ट की सीमा के पास न आ जाएं. (सबसे अच्छा विकल्प: बड़े पेजों पर, मोबाइल रेंडरिंग ओवरहेड को रोकता है. modern-web-guidance टूल यह पक्का करता है कि content-visibility सिर्फ़ ऑफ़स्क्रीन एलिमेंट पर लागू हो. साथ ही, इसे contain-intrinsic-size के साथ जोड़ा जाता है. इस कॉन्टेक्स्ट के बिना, बेस मॉडल इसे ग्लोबल तौर पर लागू कर सकता है. इससे, स्क्रोल करने के दौरान लेआउट में काफ़ी बदलाव हो सकते हैं.)

.book-item {
  display: flex;
  margin: 1rem;
  content-visibility: auto;
  contain-intrinsic-size: auto 350px;
}

7. लागू करना और पुष्टि करना

अंतरों का विश्लेषण करने और प्लान B को ऑप्टिमाइज़ किए गए तरीके के तौर पर पहचानने के बाद, इसे प्रोजेक्ट पर लागू किया जा सकता है. अब देखा जा सकता है कि मॉडर्न वेब गाइडेंस के इन नियमों से, असल में Lighthouse स्कोर पर क्या असर पड़ता है.

एजेंट, बिल्ट-इन fetchpriority लागू करता है, Speculation Rules API सेट अप करता है, और माइक्रोटास्क यिल्डिंग जोड़ता है. Lighthouse की फ़ाइनल रिपोर्ट जनरेट होने पर, मोबाइल स्कोर, शुरुआती 100 में से 61 से बढ़कर बेहतर हो जाता है.

आपने आधिकारिक तौर पर लेगसी कोड को मॉडर्न बना दिया है.

8. अहम ज़रूरतों के हिसाब से बदलाव करना

इस तरीके से, modern-web-guidance लागू करने पर आपके ऐप्लिकेशन का आकलन किया जाता है. साथ ही, यह भी देखा जाता है कि यह मॉडर्न वेब डेवलपमेंट के सबसे सही तरीकों का पालन कैसे करता है. आगे बढ़ने पर, अलग-अलग कॉन्फ़िगरेशन के साथ एक्सपेरिमेंट करें:

  • नई सुविधा जोड़ना: फ़्लोटिंग हेडर का सुझाव दें, जो स्क्रोल करने पर छिप जाता है, ताकि स्क्रीन स्पेस को ज़्यादा से ज़्यादा किया जा सके.
  • अलग-अलग बेसलाइन टारगेट के साथ एक्सपेरिमेंट करना: प्रोजेक्ट में बेसलाइन स्टेटस को बदलकर, उसके असर को देखें.
  • खास विषयों पर फ़ोकस करना और देखें कि अलग-अलग विकल्पों से आपके कोडबेस पर क्या असर पड़ता है.

बदलाव करने से, बड़े या लेगसी ऐप्लिकेशन की मुश्किलों को समझने में मदद मिलती है. साथ ही, रिफ़ाइन करने, टेस्ट करने, बनाने, और दोहराने में भी मदद मिलती है.

9. अगले चरण

मॉडर्न वेब गाइडेंस का इस्तेमाल करने के बारे में ज़्यादा जानकारी पाने के लिए, मॉडर्न वेब गाइडेंस के कमांड का दस्तावेज़ और DevTools for Agents देखें.

अगर आपके पास मॉडर्न वेब गाइडेंस के बारे में कोई सवाल है या आपको कोई सुझाव देना है, तो GitHub रिपॉज़िटरी में कोई समस्या दर्ज करें.