6

SPAs, Shared Element Transitions, and Re-Evaluating Technology | CSS-Tricks - CS...

 2 years ago
source link: https://css-tricks.com/spas-shared-element-transitions-and-re-evaluating-technology/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SPAs, Shared Element Transitions, and Re-Evaluating Technology

DigitalOcean joining forces with CSS-Tricks! Special welcome offer: get $100 of free credit.

Nolan Lawson sparked some discussion when he described a noticeable shift away from single-page applications (SPAs):

Hip new frameworks like Astro, Qwik, and Elder.js are touting their MPA [multi-page application] with “0kB JavaScript by default.” Blog posts are making the rounds listing all the challenges with SPAs: history, focus management, scroll restoration, Cmd/Ctrl-click, memory leaks, etc. Gleeful potshots are being taken against SPAs.

I think what’s less discussed, though, is how the context has changed in recent years to give MPAs more of an upper hand against SPAs.

It seems a number of folks really clung to that first part because Nolan published a follow-up to clarify that SPAs are far from doomed:

[T]he point of my post wasn’t to bury SPAs and dance on their grave. I think SPAs are great, I’ve worked on many of them, and I think they have a bright future ahead of them. My main point was: if the only reason you’re using an SPA is because “it makes navigations faster,” then maybe it’s time to re-evaluate that.

And there’s good reason he says that. In fact, the first article specifically points to work being done on Shared Element Transitions. If they move forward, we’ll have an API for animating/transitioning/sizing/positioning elements on page entrance and exist. Jake Archibald demonstrated how it works at Google I/O 2022 and the video is a gem.

If you’re wondering how one page can transition into another, the browser takes screenshots of the outgoing page and the incoming page, then transitions between those. So, it’s not so much one page becoming another as much as it is the browser holding onto two images so it can animate one in while the other animates out. Jake says what’s happening behind the scene is a DOM structure is created out of pseudo-elements containing the page images:

<transition-container>
  <image-wrapper>
    <outgoing-image />
    <incoming-image />
  </>
</>

We can “screenshot” a specific element if we want to isolate it and apply a different animation from the rest of the page:

.site-header {
  page-transition-tag: site-header;
  contain: paint;
}

And we get pseudo-elements we can hook into and assign custom @keyframe animations:

<!-- ::page-transition=container(root)  -->
<transition-container>
  <!-- ::page-transition-image-wrapper(root)  -->
  <image-wrapper>
    <!-- ::page-transition-outgoing-image(root) -->
    <outgoing-image />
    <!-- ::page-transition-incoming-image(root) -->
    <incoming-image />
  </>
</>

Dang, that’s clever as heck!

It’s also proof in the pudding of just how much HTML, CSS, and JavaScript continue to evolve and improve. So much so that Jeremy Keith suggests it’s high time we re-evaluate our past judgment of some technologies:

If you weren’t aware of changes over the past few years, it would be easy to still think that single page apps offer some unique advantages that in fact no longer hold true. […] But developers remain suspicious, still prefering to trust third-party libraries over native browser features. They made a decision about those libraries in the past. They evaluated the state of browser support in the past. I wish they would re-evaluate those decisions.

The ingredients for SPAs specifically:

In recent years in particular it feels like the web has come on in leaps and bounds: service workers, native JavaScript APIs, and an astonishing boost in what you can do with CSS. Most important of all, the interoperability between browsers is getting better and better. Universal support for new web standards arrives at a faster rate than ever before.

HTML, CSS, and JavaScript: it’s still the best cocktail in town. Even if it takes a minute for it to catch up.

DigitalOcean joining forces with CSS-Tricks! Special welcome offer: get $100 of free credit.

Leave a Reply Cancel reply

Comment

Name

Email

Website

Save my name, email, and website in this browser for the next time I comment.

Get the CSS-Tricks newsletter

multi-page-apps.jpg?fit=1200%2C600&ssl=1&resize=350%2C200

Have Single-Page Apps Ruined the Web? (“Transitional Apps”)

A big heaping 19-minute bowl of not-too-hot, not-too-cold baby bear porridge website building from Rich Harris. I've certainly overheard more than my fair share of arguments about Single Page Apps (SPAs) vs Multi-Page Apps (MPAs). Although it's only recently that I've heard people put an acronym to MPA, and it…

November 1, 2021
website-lightning.png?fit=1200%2C600&ssl=1&resize=350%2C200

Other Ways to SPAs

That rhymed lolz. I mentioned on a podcast the other day that I sorta think WordPress should ship with Turbolinks. It's a rather simple premise: Build a server-rendered site. Turbolinks intercepts clicks on same-origin links. It uses AJAX for the HTML of the new page and replaces the current page…

August 21, 2019
page-transitions.jpg?fit=1200%2C600&ssl=1&resize=350%2C200

Rendering Spectrum

Here are the big categories of rendering websites: Client: ship a and let a JavaScript template render all of it.Static: pre-render the HTML.Server: let a live server process requests and generate the HTML response. They are not mutually exclusive. A website could statically pre-render 75% of it's pages…

November 24, 2020
Jetpack Logo

The related posts above were algorithmically generated and displayed here without any load on our servers at all, thanks to Jetpack.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK