Best Website-BuildersBest Website-Builders
    What's Hot

    Indicting Trump Is Like Arresting Tupac, Boosts Popularity

    March 21, 2023

    Warnings against 'reckless' weight loss surgery abroad

    March 21, 2023

    Met police found to be institutionally racist, misogynistic and homophobic

    March 21, 2023
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    Best Website-BuildersBest Website-Builders
    • Home
    • CSS

      CSS exam essay

      March 21, 2023

      Weiss Asset Management LP will reduce its holding in Juniper II Corp. (NYSE:JUN).

      March 20, 2023

      8 semantic HTML tags to make your website accessible, clean and modern

      March 20, 2023

      CSS Entertainment (CSSE) and Allen Media Group join Redbox as partners

      March 20, 2023

      European Bank Bonds, Stocks Fall After Surprise AT1 Wipeout of CS

      March 20, 2023
    • Joomla

      Web Hosting: 8 Elements Every Entrepreneur Should Look For

      March 20, 2023

      VS Code Extension for In-Browser Development, WapuuGotchi Gamification Plugin & More – WP Tavern

      March 20, 2023

      How Superior Web Hosting Support Can Drive Business Success

      March 17, 2023

      PANDACU Studio Website Development Cooperation First Page Sage SEO Dsign Chicago adstargets Cardinal Digital Agency

      March 16, 2023

      Bluehost Review: Best Solution for Your Web Hosting Needs? – WISH-TV | Indianapolis News | Indiana Weather

      March 15, 2023
    • PHP

      Emma Chamberlain shuts down online shop after charging DMs $10,000

      March 20, 2023

      Aurora man arrested for allegedly poisoning wife with smoothie

      March 20, 2023

      Christina Ricci said she was nearly sued for a sex scene

      March 20, 2023

      Gen Z adults pay rent with credit cards

      March 20, 2023

      Adam Sandler Wins Mark Twain Award for American Humor

      March 20, 2023
    • UX

      Aura Network Launches Xstaxy Mainnet, Making NFTs Accessible To The Mainstream

      March 21, 2023

      ForgeRock Enterprise Connect Passwordless Mitigates Risk of Password-Based Attacks

      March 21, 2023

      Wipro and Secret Double Octopus provide enterprises with a strong authentication mechanism

      March 21, 2023

      What is End User Experience Monitoring (EUEM)?

      March 20, 2023

      Payment transparency is widespread.What You Need to Know | News, Sports, Jobs

      March 20, 2023
    • Web Builders
      1. Web Design
      2. View All

      What Comes First in Website Development — Design or Copy?

      February 2, 2023

      Modern Campus Honors Best Higher Education Websites of 2022

      February 2, 2023

      Premier SEO Consultant in Las Vegas, Nevada with Unparalleled Customer Service

      February 2, 2023

      Can Religious Freedom Be Saved? This group is racing the clock to teach America’s first freedom

      February 2, 2023

      How i Create New Google Account

      February 7, 2023

      CWT powers tools for meeting and event planners

      January 31, 2023

      Best Website Builder – Website Builders

      January 24, 2023

      Is There A Market For Rap-Themed Slot Games? – Rap Review

      January 19, 2023
    • WordPress

      Acer’s new e-bike uses AI to learn how to ride around town

      March 21, 2023

      The RTX 4080 gets a big upgrade thanks to Asus and Noctua

      March 21, 2023

      Hitachi Energy confirms data breach after being hit by Clop ransomware

      March 20, 2023

      Don’t keep your guests waiting on poor Wi-Fi. Offer Aruba Instant On.

      March 20, 2023

      iPhone 15 Pro leak suggests it may make controversial button changes

      March 20, 2023
    • Realtoz
      • Our Other Sites
    • More News
    Best Website-BuildersBest Website-Builders
    Home » JavaScript hydration is a workaround, not a solution
    JavaScript

    JavaScript hydration is a workaround, not a solution

    websitebuildersnowBy websitebuildersnowJune 8, 2022No Comments6 Mins Read
    Facebook Twitter LinkedIn Telegram Pinterest Tumblr Reddit WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    In web development, hydration is a technique for adding interactivity to server-rendered HTML. This is a technique where client-side JavaScript transforms a static HTML web page into a dynamic web page by attaching event handlers to HTML elements.

    However, attaching event handlers to the Document Object Model (DOM) is not the most difficult and expensive part of hydration.

    This article explains why I believe hydration is an overhead. This is a memory consuming and slow booting hack especially on mobile. For the purposes of this article, let’s define overhead as work that can be avoided and still lead to the same end result.

    Digging deeper into hydration

    Mishko Hevery

    Miško Hevery is Chief Technology Officer at Builder.io. As CTO, Miško oversees the technical department that powers the Builder.io application and software. Before he joined Builder.io, he created open source platforms for Google, including Angular and AngularJS, and was a co-creator of Karma. During his time at Google, he brought the testing culture to his Google with his blog. Before focusing on making the web better, he believes testing is the key to success.

    The hard part of hydration is knowing which event handlers you need and where they should be attached.

    • what: An event handler is a closure that contains the behavior of an event. What should happen if the user triggers this event.
    • Where: location of DOM element where WHAT should be attached (including event type)

    An additional complication is what is the closure that is closed APP_STATE When FW_state:

    • APP_STATE: application state. APP_STATE What most people think of as states.without it APP_STATEyour application has nothing dynamic to show to the user.
    • FW_state: The internal state of the framework.without it FW_state, the framework doesn’t know which DOM nodes to update or when the framework should update them. Examples include references to component trees and render functions.

    So how, what and where to recover? Download and run the rendered component in HTML. This is the expensive part.

    In other words, hydration APP_STATE When FW_state By eagerly running the app code in the browser, it includes:

    • Downloading component code.
    • Running component code.
    • what to recover (APP_STATE When FW_state) and WHERE to get the event handler closure.
    • Attach WHAT (event handler closure) to WHERE (DOM element).

    Let’s call the first three steps the recovery phase.

    recovery That’s when the framework is trying to rebuild your application. Rebuilds are expensive because the application code must be downloaded and executed.

    Recovery is directly proportional to the complexity of the page being hydrated and can easily take 10 seconds on mobile devices. Recovery is the expensive part, so most applications have sub-optimal startup performance, especially on mobile.

    Recovery is also an overhead. Reconstructs information already collected by the server as part of server-side rendering (SSR) or static site generation (SSG). Instead of sending the information to the client, the information was discarded. As a result, the client has to do a costly Recovery to rebuild what the server already had. Recovery could have been avoided if only the server had serialized the information and sent it along with the HTML to the client. The serialized information saves the client from having to eagerly download and execute every component in her HTML.

    In other words, the re-execution of code on the client that the server has already executed as part of SSR/SSG is what makes hydration pure overhead.

    Resumability: a no-overhead alternative to hydration

    To remove the overhead, the framework should not only avoid Recovery , but also attach WHAT , step 4 above, to WHERE .

    Avoiding this cost requires three things:

    • All necessary information serialized as part of the HTML. WHAT, WHERE, APP_STATEWhen FW_ state.
    • A global event handler that relies on event bubbling to intercept all events. This eliminates the need to actively register every event individually on a particular DOM element.
    • A factory function that can lazily recover event handlers (WHAT).

    The above setup is resumable because it allows the server to pick up where it left off without having to redo work it has already done. By lazily creating her WHAT in response to the user’s event, we avoid all the unnecessary work that happens with hydration. All this means no overhead.

    memory usage

    A DOM element retains event handlers for the lifetime of the element. Hydration creates all listeners eagerly, so it needs to allocate memory on startup.

    Resumable frameworks, on the other hand, do not create event handlers until the event is triggered. Therefore, it consumes less memory than hydration. Additionally, the event handler is freed after execution and the memory is returned.

    In a way, releasing memory is the opposite of hydration. It’s as if the framework lazily hydrates certain WHATs, executes them, and then dehydrates them. There is not much difference between his 1st and nth execution of the handler.

    performance difference

    To bring this idea to life, we built Qwik, a framework designed around “resumability” and enabling rapid startup. To demonstrate the impact of resumability, we created a demo of a ToDo app running on Cloudflare Edge. The page becomes operational in about 50 ms.

    I’ve also redone website builder.io using the resumable strategy (and Qwik). Using Qwik (and our other solution, Partytown), we were able to reduce the JavaScript on our site by 99% and achieve a PageSpeed ​​score of 100/100. (You can also use hydration to visit the old page to compare and experience the performance difference.)

    Conclusion

    Simply put, hydration is overhead due to duplication of work. The server uses WHERE and WHAT (APP_STATE When FW_state), but the information is discarded instead of being serialized for the client. The client then receives HTML that does not have enough information to reconstruct the application. Due to the lack of information, the client must eagerly download and run the application to restore the WHERE and WHAT.

    An alternative approach is resumability. Resumability focuses on transferring all information (WHERE and WHAT) from the server to the client. Only user interactions force the client to download the code that handles that particular interaction. The client is not duplicating work from the server. So no overhead.

    group Created by sketch.



    Source link

    Share this:

    • Tweet
    • Email
    • Pocket
    • Mastodon
    • WhatsApp
    • Telegram
    • Share on Tumblr
    • Print
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    Previous ArticleWhat You Need to Know – Forbes Advisors
    Next Article Introducing JHipster: A full-stack framework for Java and JavaScript
    websitebuildersnow
    • Website

    Related Posts

    Forms: Run function when field changes? – JavaScript – SitePoint Forum

    March 20, 2023

    TypeScript 5 – Smaller, Simpler, Faster

    March 20, 2023

    JavaScript Libraries Enable Developers to Add AI Capabilities to the Web

    March 20, 2023
    Add A Comment

    Leave a Reply Cancel reply

    Top Posts

    Subscribe to Updates

    Get the latest sports news from SportsSite about soccer, football and tennis.

    Advertisement
    Demo

    This website provides information about CSS and other things. Keep Supporting Us With the Latest News and we Will Provide the Best Of Our To Makes You Updated All Around The World News. Keep Sporting US.

    Facebook Twitter Instagram Pinterest YouTube
    Top Insights

    Indicting Trump Is Like Arresting Tupac, Boosts Popularity

    March 21, 2023

    Warnings against 'reckless' weight loss surgery abroad

    March 21, 2023

    Met police found to be institutionally racist, misogynistic and homophobic

    March 21, 2023
    Get Informed

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    © 2023 bestwebsite-builders. Designed by bestwebsite-builders.
    • Home
    • About us
    • Contact us
    • DMCA
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.