Be careful with legacy code :)
Addy Osmani
@addyosmani
Engineering leader, • Author • Great user & developer experiences • • •
Addy Osmani’s posts
Native <img> lazy-loading is coming to the web! bit.ly/loading-attrib <img loading=lazy> defers offscreen images until the user scrolls near them. Shipping in Chrome ~75 bit.ly/loading-i2s
A fun generator for CSS-only section separators! bit.ly/css-sections
remove.bg is amazing. Free service to remove the background of any photo 100% automatically.
TIL CSS "background-repeat: round" bit.ly/bgroundtips ~ repeats background images without clipping ✂️
A black hole simulation in 140 bytes of JavaScript: frankforce.com/?p=6378 🤯
for(i=0;i<2e3;x.fillRect(i?960+i*S(F=260*(t+9)/i+S(i*i)):0,i?500+.2*(2*i*C(F)+2e4/i):0,K=i++?S(i)*9:2e3,K))x.fillStyle=R(99*i,2*i,i,i?1:.4)
VSCode now has bracket pair colorization natively baked in! Aims to be faster than the popular Bracket Pair Colorizer extension. Smooth so far: bit.ly/vscbp
The "Software Engineering at Google" book is now free to read online: bit.ly/swe-book. Great insights on improving code quality & scaling engineering teams.
read image description
ALT
CSS "content-visibility:auto" is amazing: skip rendering & painting offscreen content until needed. I got a ~1s faster render on a long HTML document on desktop, ~3s on mobile.
web.dev/content-visibi
read image description
ALT
"Your UI doesn't need to map one-to-one with your data's fields and values". Great thinking on simplicity from
Introducing "Learning Patterns": patterns.dev - a free 435+ page book on JavaScript + React design & performance patterns from and I. On the web, ePub & PDF.
read image description
ALT
A full free Stanford course on Web Security: stanford.io/2UHIu65 by
🍪 HTTP(S), Cookies, Sessions
🛡Same Origin Policy
👿 Cross-Site Scripting (XSS)
☠️ Cross-Site Script Inclusion
🔑 WebAuthn
and more.
Tip: target="_blank" on links to other sites can expose your site to performance and security issues. To fix, add rel="noopener" or rel="noreferrer" to these links: bit.ly/relnoop ✅
TIL the CSS "-webkit-line-clamp" property truncates multi-line text: bit.ly/lineclamp. It's supported in Chromium, Firefox and Safari! bit.ly/caniuse-lc
Things to look for in a code review: Code is...
- Well designed
- Readable by others
- Doing what the author intended
- No more complex than needed
- Not degrading system code health
- Commented with the why vs. what
- Appropriately tested
- Sufficiently documented
How Spotify makes text on images more readable: a CSS linear-gradient overlay. More common these days, but still an effective technique for better color contrast.
read image description
ALT
Tip: Font size isn’t always the best way to emphasize text. Try font color and font weight instead. h/t
read image description
ALT
DevTools now shows inactive CSS properties. Hovering explains why the rule has no visible effect. So nice.
read image description
ALT
1000+ open-source UI designs: uidesigndaily.com ~ Sketch, Figma and PhotoShop sources for all kinds of web projects.
*Must read* for web developers: an inside look at how modern browsers work by
1️⃣ bit.ly/browsers-pt1
2️⃣ bit.ly/browsers-pt2
3️⃣ bit.ly/browsers-pt3
4️⃣ bit.ly/browsers-pt4
The <img> element now supports lazy-loading, async decoding and many other features: bit.ly/img-cwv I wrote about how to optimize UX & the Core Web Vitals with it.
read image description
ALT
The new CSS aspect-ratio property lets you set the proportion of any element's dimensions without padding-top hacks! Read about it in web.dev/aspect-ratio by
Excited to announce "Learning Patterns": a free new visual book on the latest JavaScript design, rendering, and performance patterns from and I. Available in ePub/PDF and on web, coming this year.
read image description
ALT
An excellent guide to the proper use of animation in UX: bit.ly/animation-in-ux
GIF
The specification for native image lazy-loading has been merged into the HTML standard! github.com/whatwg/html/pu 🎉
Huge thanks to and many others! About: bit.ly/lazyl
read image description
ALT
Tip: highlight images missing alt text with img:not([alt])
read image description
ALT
CSS aspect-ratio is now supported cross-browser! It lets you set the proportion of an element's dimensions without padding-top hacks 😍 Read more in web.dev/aspect-ratio mdn.io/aspect-ratio
read image description
ALT
Improved exception messages: Goodbye "undefined is not a function". Hello "foo.bar is not a function"
"Your UI doesn't need to map one-to-one with your data's fields and values". Great thinking on simplicity from (whose Refactoring UI book is A+)
read image description
ALT
read image description
ALT
Tips for efficiently Googling. Search by:
Exact match > "javascript modules"
Scope to site > site:<domain> js
After a date > javascript after:2021
Before > javascript before:2019
Exclude a phrase > javascript -es5
Number range > javascript 2015..2021
Wildcard > "fix the * error"
*Must read* for web developers: how modern browsers work by
1️⃣ bit.ly/browsers-pt1
2️⃣ bit.ly/browsers-pt2
3️⃣ bit.ly/browsers-pt3
4️⃣ bit.ly/browsers-pt4
and browser.engineering by
read image description
ALT
Be humble, communicate clearly, and respect others. It costs nothing to be kind, but the impact is priceless.
The `inputmode` attribute is great ✨ Hints to the browser what virtual keyboard to show on mobile: bit.ly/inputmode
read image description
ALT
Tip: Chrome can measure how much unused JavaScript is on your page bit.ly/unused-js
DevTools > top-right menu > More tools > Coverage
read image description
ALT
Shipped! now let's you control web font loading using `font-display`. Say hello to the `display` parameter 🎉
What's font-display? font-display.glitch.me
Want to create responsive images fast? Try responsivebreakpoints.com. Give it an image and it:
🖥️ Determines optimal breakpoints
🖼️ Generates <img srcset> code
📦 Creates a .zip of responsive images!
via
read image description
ALT
url.searchParams is so nice for getting/setting query string params.
Clean Code concepts for JavaScript: bit.ly/clean-code-js ~ a huge collection of patterns for writing readable, reusable, and refactorable code. By
Tip: Get native-app like sharing in a few lines of JS with the Web Share API: web.dev/web-share. Supports sharing links, text & files.
The CSS :is() pseudo-class will be useful for writing repetitive selectors in a more compact form: bit.ly/is-wh ~ covers it coming to browsers.
read image description
ALT
Priority Hints: hint the `importance` of a resource to prioritize downloading it sooner/later:
<img importance=low>
<img importance=high>
<img importance=auto> (default)
Works on <img>, <link> and fetch()
📗 Spec: wicg.github.io/priority-hints/
🏃♀️ Origin Trial: bit.ly/hints-experime
read image description
ALT
Tip: You can name capture groups for Regular Expressions in JavaScript. Define a named capture in angle brackets <> and they get returned under .groups.
read image description
ALT
Tip: In , hold shift while hovering over a request and it will highlight the initiator in green and dependencies in red.
Tip: highlights what elements have scroll overflows! Useful to find what DOM nodes have an unexpected scrollbar.
DevTools Tip: $_ in the Console returns the value of the last expression evaluated.
My lessons from the decade:
* You never stop learning
* You can't know everything
* Failure is healthy & helps us grow
* Your biggest competition is yourself
* Communication is key in life & work
* Be kind & empathize with others
* Value friends & family
* Get enough sleep :)
Tip: Get the unique values of an array in JavaScript.
read image description
ALT
We’ve improved <img> lazy-loading in Chrome! bit.ly/lazy-updates The new thresholds for when we load <img loading=lazy>:
* Offer *much* better data-savings
* Are closer to JavaScript lazy-loading libraries
* Are rolling out to Chrome 79+
New: Inspect Element in now has a tooltip of CSS properties! Displays when hovering over elements (via )
read image description
ALT
Tip: Use curly braces in the command-line to quickly create multiple related files with less typing.
A Netflix web performance case study: medium.com/dev-channel/a-
⚡ 50% faster Time-to-Interactive (logged-out homepage)
- ✂️ JS libraries by 200KB
- Client-side React ➡️ vanilla JS
- React used server-side
⚡ 30% faster subsequent navigations
- Prefetch React for sign-up process
Optional Chaining & Nullish Coalescing are coming to JavaScript! They're short, readable and are both available to try in Chrome Canary 🎉
v8.dev/features/optio
v8.dev/features/nulli
read image description
ALT
ResizeObserver lets us observe changes to the layout size of elements: bit.ly/ro-safari It's in the latest Safari!
Now in *all* modern browsers, we can efficiently design components responsive to their container vs. just the viewport.
The CSS :is() pseudo-class is useful for writing repetitive selectors in a more compact form: goo.gle/cssis by covers it well!
read image description
ALT
Tip: Get the unique values of an array in JS. Use ES2015 Set() and ...rest to discard duplicate values.
Tip: Get native-app like sharing in a few lines of JS with the Web Share API: web.dev/web-share. Supports sharing links, text & files.
read image description
ALT
Tip: Set width & height on your <img> elements. This now allows modern browsers to infer their intrinsic size pre-download, reducing layout shifts.
Wow. You can create and edit full diagrams in your editor with the Draw.io VS Code extension: bit.ly/draw-vsc
"Use Grid for layout, Flexbox for components": bit.ly/gr-fl Great tips on how to decide what fits your use-case by
Tip: Shave up to 90% off the size of Google Fonts requests by declaring only characters you need with &text: bit.ly/fonts-text
Use React? Render large lists efficiently with react-window: bit.ly/react-window ~small library for virtualizing lists & grids. Renders what users can see vs all your items at once ⚡️
Puppeteer Recorder is game-changing for tests: bit.ly/pptr-recorder ~ This Chrome extension records interactions & *generates* replay scripts 🤯
Trying responsively.app ~ test responsive designs on target screens side-by-side. Includes DevTools, click/scroll mirroring & batch screenshot export.
📣 "The Cost Of JavaScript In 2018"
Algorithms and data structures implemented in modern JavaScript: bit.ly/js-algos & bit.ly/more-algos. Treasure trove of examples to learn from.
When you suffer from imposter syndrome, remember that everyone had to learn new things at some point.
e.g. Google’s Larry Page w/web dev:
read image description
ALT
Tip: JavaScript's Array.from() accepts a second argument that's a `map` function. Useful for calling on each element of an array you created.
Tip: can pin Live Expressions to the top of Console to monitor values in real-time! ✨
Logpoints in are great. Log messages to Console without console.log() calls in your code - persists across page reloads too!
Becoming a good engineer is about collecting experience. Each project, even small ones, is a chance to add new techniques and tools to your toolbox.
JavaScript & CSS code coverage are out of experiments in . Useful for discovering potential size savings in your bundles ✂️🔥
Have low-resolution images? Enlarge them & improve their quality with ojoy.netlify.app. All client side. Powered by ML using UpscalerJS & TensorFlow.js.
📢 Announcing… quicklink! <1KB library to..
⚡ Automatically prefetch links in the viewport during idle time
⏳ Attempt to make next-page navigations load faster
📡 Data-considerate: doesn't prefetch on 2G or if Data Saver on
github.com/GoogleChromeLa
read image description
ALT
AVIF is an image format that compresses to a smaller size than WebP or JPEG bit.ly/avif-pe It's in Chrome 85, behind a flag in Firefox & can be a progressive enhancement!
read image description
ALT
Peacock for VS Code is *awesome*: bit.ly/peacock-vsc ~ quickly change the color of each workspace. Makes it easier to identify different projects.
Tip: can now override the content of Fetch/XHR requests! Great for mocking APIs without waiting on backend changes!
This and lots more in Chrome 117: bit.ly/wnd117
This isn't a photo. It's a pure CSS-only landscape bit.ly/css-landscape by 🤯Quick video on process: bit.ly/css-landvid
