How do Nike and Apple make such smooth and touch friendly carousels with pure CSS?
/* tl;dr */
.carousel {
scroll-snap-type: x mandatory;
}
.carousel .item {
scroll-snap-align: start;
}
More detail 👇
A cure for React useState hell?
You may not realize how easily you can replace useState with useReducer and simplify your state management
You can read more in my latest blog post:
Are you loading images as optimally as you can?
Do you know how and when to use decoding=async, loading=lazy, fetchpriority, <picture>, aspect-ratio, or srcset?
A deep dive on optimally loading images in my latest blog post:
PSA: please stop using strings concatination to create and edit URLs in JS
All major browsers have great built-in functionality for URL parsing & manipulation:
This is one you need to know.
JS has a built-in function for deep cloning objects called `structuredClone`, which can handle:
😍 Deeply nested objects and arrays
🌎 Many types, like Date, Set, Map, etc
➰ Circular references
More in my latest article:
Performance tip: make your page load feel more instant by using priority hints to help the browser prioritize the most critical resources
More you can do with priority hints in 🧵:
Performance tip: try the `decoding` attribute for images to allow decoding to be async and not block the main thread, allowing your content to display faster
How does Tesla make that beautifully smooth full page swipe effect on their homepage?
/* tl;dr */
.container {
scroll-snap-type: y mandatory;
}
.section {
scroll-snap-align: start;
scroll-snap-stop: always;
}
More detail 👇
The `Intl` object in JS is so valuable, yet so underutilized
Learn how to generate friendly relative time strings from a given date - like "in 10 minutes" or "last week" or "tomorrow" - with 0 dependencies in my latest blog post:
Do you know about ReturnType in TypeScript? What about Awaited or Parameters?
Utility types can unlock a lot of power to keep your code type safe, even when your npm packages aren't perfect
More magic you can do with utility types in my latest article:
The `satisfies` operator in TypeScript 4.9 is a game changer
Here is a quick overview of how it compares to a couple alternative ways of annotating types
Learn more about the `satisfies` operator here:
How Apple makes those crazy 3D effects as you scroll
While this is not the best for performance/usability/accessibility, it's fun to see how they do it
The CSS Working Group is debating over the best way to define nesting in CSS, and want your input!
Which do you like best?
You can vote in the official poll here:
JavaScript Maps (new Map()) are more performant, ergonomic, and overall useful than you might think.
You may want to consider using them more often than you likely are.
Full video is now out!
How Apple makes their beautiful hamburger menu in *pure CSS* (no JS!)
<!-- tl;dr -->
<input type="checkbox" ... />
<style>
.checkbox:checked + .menu {
/* animate */
}
</style>
More detail 👇
CSS has a variety of layout algorithms to choose from
It is useful to understand the differences, as some CSS properties behave differently in each layout mode
How does Apple make that awesome frosted glass effect on their site header in CSS?
tl;dr backdrop-filter: blur(20px) saturate(180%)
Better explanation 👇
Quick tip: avoid plain objects when you need to frequently create and remove keys, and use a Map instead
You can get better performance and ergonomics
More cool things you can do with Maps in my latest blog post:
Are you ever debugging in Node.js and realize your terminal leaves a lot to be desired...
Did you know that it takes just 2 seconds to connect any Node process to your browser devtools and have fully interactive debugging 🐛?
Read on in our article:
I know we get caught up in our micro preferences for frameworks.
But let’s not lose sight of the fact that truly:
@reactjs
is a phenomenal framework
@vuejs
is a phenomenal framework
@nextjs
is a phenomenal framework
@nuxt_js
is a phenomenal framework
@sveltejs
is a phenomenal…
Web perf tip: avoid using background-image in CSS
For faster loading images, use <img /> anywhere possible, for better optimization options such as the srcset & sizes attributes
If you don't already know... I'm a huge fan of the new `satisfies` operator in TypeScript 4.9
I've compiled the best examples I've found on using the operator, as well as a few helpful notes to make the most of it
Latest blog post now live:
Browser-native deep object cloning in JS is finally here, and it's awesome
structuredClone() can:
- copy deeply nested data
- handle many data types like Map/Set/Regex/etc
- even handle circular references
Performance is great as well ⚡️
Do you know the difference between a Map and a WeakMap and when to use which?
Or why you would even want to have objects as keys and what use cases this unlocks?
More in the full article:
Countries with the best food I’ve ever had (subjective):
1. India
2. Thailand
3. Mexico
4. China
5. France
6. Japan
7. Malaysia
8. Brazil
9. Portugal
10. Italy
…
Absolute worst: England
It’s insane what happens when you connect LLMs to a visual editor.
Generate responsive designs and apps with AI, edit them with natural language, and convert to code for any framework.
This is not a hypothetical future or "private beta", its available right now for everyone:
One new way you can make fetch() more elegant is to use the new Error.prototype.cause property in JS:
const res = await fetch(...)
if (!res.ok) {
throw new Error('...', { cause: res })
}
...
catch (err) {
if (err.cause.status === ...) {
// Handle each status
}
}
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.
Just ship it.…
What is Server-Driven UI?
It's an emerging technique for:
- more component-driven development
- a balance of personalization and performance
- better content workflows for teams
More in the vid:
Performance tip: don't forget to dedupe your modules!
In many cases, you may be loading the same package multiple times
Try `npm dedupe` or `npx yarn-dedupe` to ensure you shed unneeded duplicates
My personal likes/dislikes of the popular frameworks:
React: I love TSX and hooks.
Dislike: useEffect, callback arrays, and over pushing immutability.
Vue: I love SFCs, simple proxy-based mutable state management.
Dislike: would like to see a solution to having less…
JS perf tip: date libraries can hurt your site speed more than you expect
Consider browser native alternatives under `Intl` for faster execution and smaller bundles
we just finished porting a major ML project from JS to python only for it to be…. about 100x slower
moving it back to JS and using a bit of C where needed has given us an insane perf boost
I don’t have a college degree of any kind. I’ve never taken a CS class.
If you like my content then you agree that you don’t need formal education to have valuable knowledge about coding.