Image decoding is said to be asynchronous if it does not prevent presentation of other content.
Applying this to images "below the fold" can improve performance by allowing visible content to be painted to the screen earlier.
Applying decoding="async" to images "above the fold" can cause flashing - as other content such as text can be painted to the screen before images are decoded. After they've been decoded they will appear to pop in.
If we want to ensure an image is decoded before content is painted to the screen we need to use decoding="sync", like this:
<imgsrc="./avatar.png"decoding="sync"/>
The default state for this attribute is auto, which lets the browser decide whether to use async or sync decoding:
There is a proposal that will allow us to measure how long some elements take to render. Adding the elementtiming attribute to certain elements, such as images, will expose information about their loading time via the PerformanceElementTiming interface.
We can force yarn to install a specific version of a nested dependency. This can be useful if a nested dependency has a bug or security vulnerability.
To change the version of a dependency of a dependency installed by yarn, we simply need to add the name of the package and the version number we want to the resolutions object of our package.json, like this:
{"resolutions":{"colors":"1.4.0"}}
Adding the above two fields in package.json will make sure the nested dependency colors will be installed at version 1.4.0, regardless of what the package requiring actually specifies.
We can achieve a similar thing with npm but not natively. We can use the npm-force-resolutions package, like this:
I was already aware of the new media queries in CSS Media Queries Level 5 that aim to improve accessibility on the web - such as prefers-reduced-motion.
Today I learned about a new media query, which hasn't been widely written about yet: prefers-reduced-transparency.
"Reduce transparency" can be toggled in the macOS system preferences like other accessibility options. It's a system-wide option and when I turn it on, I immediately notice the macOS status bar changes from translucent to opaque. I find the menu options a lot easier to read like this, so maybe I'll keep it turned on.
Back to CSS: if the user has turned on "Reduce transparency" then we need to reduce, or even disable, the amount of transparency we're using on our pages and web apps.
When would people want to reduce transparency on a web page? The first example that came to my mind is text on top of images. I thought of the links to news articles on the BBC home page. Here, we can see text directly on top of an image:
The subtitle text in the example above is problematic, especially at busier parts of the article image.
Interestingly, on the same BBC page, we can also see an example of how the developers could style the above content for users that have prefers-reduced-transparency turned on. The text is directly beneath the image, rather than over it.
This solution results in the article headline on an opaque background which means there are no transparent elements.
Using the prefers-reduced-transparency media query will allow developers to show the first design to users that haven't set a "Reduce transparency" preference, and the design in the second image to users who have enabled it.
We can tell TypeScript that a value is not null with the post-fix operator !. By adding the ! at the end of a function, we are saying "this function does not return null here", even if it normally could at other times.
For example:
// No post-fix !const countryDropdown = document.querySelector('select#country');// countryDropdown is Element | null// With post-fix !const yearDropdown = document.querySelector('select#year')!;// yearDropdown is Element
In the example above, if we know for certain that <select id="year"> exists in the DOM, then by using the non-null assertion operator ! TypeScript knows that yearDropdown is an Element. This means we can avoid having to do null type checking before interacting with the yearDropdown variable.
You can move the cursor in a terminal window with the mouse by
holding the alt key and clicking in the terminal window.
This works in the native macOS terminal, iTerm and the terminal
inside VS Code.