Alex MacArthur's Avatar

Alex MacArthur

@macarthur.me.bsky.social

Bossing around computers in made-up languages.

31 Followers  |  20 Following  |  102 Posts  |  Joined: 07.08.2023  |  1.7121

Latest posts by macarthur.me on Bluesky

Oh my

18.06.2025 22:56 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Further confirmation of my point. βœ…

18.06.2025 22:49 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

My point confirmed. βœ…

18.06.2025 22:38 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

He’s right. This place will continue to lose if it keeps operating like this.

18.06.2025 22:21 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

much appreciated, @andrejnsimoes.com + @gregex.bsky.social!

03.06.2025 14:32 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
`document.currentScript` is more useful than I thought. After discovering and being unsure of its value, I just realized how useful `document.currentScript` can be in exposing configuration properties to `<script>` elements (and other things too).

I have learned first-hand that the document.currentScript can be useful. #javascript

macarthur.me/posts/curren...

02.06.2025 15:51 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
I think the ergonomics of generators is growing on me. I took a stab at getting more familiar with iterators, iterables, and generators. I think I'm starting to like the ergonomics.

I’ve been spending some dedicated time tinkering w/ iterators, iterables, & generators in #JavaScript. I’m still struggling a bit to find use cases in which it’s materially the best solution. But! I am liking the ergonomics more.

Blog post:

macarthur.me/posts/genera...

12.05.2025 16:25 β€” πŸ‘ 4    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0

- The lighter, resized images will be served for future page views.

I've seen many, many examples of 3000px-wide images being used for a small 300px-wide card. Now you don't even need to think about it.

Just plop a small, deferred, non-intrusive script pages with PP images. ⚑️

15.04.2025 00:19 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

- Each image will be measured, using the rendered & natural widths to determine if it could be resized more effectively.

- Eligible images will be asynchronously resized based on how they *actually* show on a large screen.

15.04.2025 00:19 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

Sickkk new feature coming to PicPerf: automatic resizing. Here's how it'll work:

- Behind the scenes, PP will headlessly render your page at a large desktop's screen dimensions.

15.04.2025 00:19 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Preview
I guess some request headers are more trustworthy than others. There's a subset of request headers that can't be modified by a spec-compliant user agent. Let's explore why they're useful for determining how and for what purpose a request was triggered.

I learned about β€œforbidden” request headers recently, which can’t be overridden by client-side JavaScript APIs. A subset also give some nice context about a request, like whether it came from someone directly navigating to a page.

Useful stuff. Wrote more here:

macarthur.me/posts/forbid...

31.03.2025 22:29 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

I think we’re over-indexing on the importance of time-to-ship and the AI tooling that minimizes it. Shipping is easier, but committing to iterating on & growing a product is still hard. That’ll probably continue to be the differentiating factor between success & failure.

11.02.2025 14:22 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
list of forbidden request headers

list of forbidden request headers

TIL about β€œforbidden” request headers. None of these can be set in the browser by JavaScript APIs like fetch() or XMLHttpRequest.

10.02.2025 15:14 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
How Do I Choose?

The approaches we've covered here are not exhaustive, but I think they do a good job at representing the various trade-offs you should consider when breaking up long tasks. Still, depending on the need, I'd probably only reach for a subset of these myself.

If I can do the work off from the main thread, I'd choose a web worker, hands-down. They're very well supported across browsers, and their entire purpose is to offload work from the main thread. The only downside is their clunky API, but that's eased by tools like Workerize and Vite's built-in worker imports.

If I need a dead-simple way to break up tasks, I'd go for scheduler.yield(). I don't love how I'd also need to polyfill it for non-Chromium users, but the majority of people would benefit from it, so I'm up for that extra bit of baggage.

If I need very fine-grained control over how chunked work is prioritized, scheduler.postTask() would be my choice. It's impressive how deep you can go in tailoring that thing to your needs. Priority control, delays, cancelling tasks, and more are all included in this API, even if, like .yield(), it needs to be polyfilled for now.

If browser support and reliability are of the utmost importance, I'd just choose setTimeout(). It's a legend that's not going anywhere, even as flashy alternatives hit the scene.

How Do I Choose? The approaches we've covered here are not exhaustive, but I think they do a good job at representing the various trade-offs you should consider when breaking up long tasks. Still, depending on the need, I'd probably only reach for a subset of these myself. If I can do the work off from the main thread, I'd choose a web worker, hands-down. They're very well supported across browsers, and their entire purpose is to offload work from the main thread. The only downside is their clunky API, but that's eased by tools like Workerize and Vite's built-in worker imports. If I need a dead-simple way to break up tasks, I'd go for scheduler.yield(). I don't love how I'd also need to polyfill it for non-Chromium users, but the majority of people would benefit from it, so I'm up for that extra bit of baggage. If I need very fine-grained control over how chunked work is prioritized, scheduler.postTask() would be my choice. It's impressive how deep you can go in tailoring that thing to your needs. Priority control, delays, cancelling tasks, and more are all included in this API, even if, like .yield(), it needs to be polyfilled for now. If browser support and reliability are of the utmost importance, I'd just choose setTimeout(). It's a legend that's not going anywhere, even as flashy alternatives hit the scene.

Good post from @macarthur.me on the various ways to break up long tasks.

macarthur.me/posts/long-t...

I especially like nice summary at the bottom:

08.02.2025 12:12 β€” πŸ‘ 13    πŸ” 4    πŸ’¬ 1    πŸ“Œ 0

Thanks Barry!

08.02.2025 15:52 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
There are a lot of ways to break up long tasks in JavaScript. It's very common to intentionally break up long, expensive tasks over multiple ticks of the event loop. But there are sure are a lot of approaches to choose from. Let's explore them.

macarthur.me/posts/long-t...

03.02.2025 13:58 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
scheduler.yield() example

scheduler.yield() example

If you’ve ever needed to break up a long JavaScript task to keep the UI responsive, you’ve probably reached for setTimeout(). Turns out there are a boatload of other options at your disposal, like scheduler.yield(). I wrote about a handful & their tradeoffs:

03.02.2025 13:58 β€” πŸ‘ 3    πŸ” 1    πŸ’¬ 1    πŸ“Œ 0
Preview
We'll soon be able to slide open a `height: auto` box with native CSS. Using JavaScript or other creative tricks to animate open a box with unknown contents will soon be a thing of the past. Let's tinker with two new approaches native to CSS.

Wrote about it more detail here:

macarthur.me/posts/modern...

25.01.2025 16:36 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
You can now opt into animating intrinsic size keywords by using "interpolate-size: allowed-keywords" on a parent element.

You can now opt into animating intrinsic size keywords by using "interpolate-size: allowed-keywords" on a parent element.

Look at what you'll soon be able to do in native CSS (currently supported in Chromium browsers):

25.01.2025 16:36 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Preview
I didn't know you could compose template literal types in TypeScript. TypeScript's string literal types are a lot more useful than I originally thought.

Short post about composing template literal types in TypeScript:

macarthur.me/posts/templa...

18.01.2025 05:55 β€” πŸ‘ 2    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0
Preview
Short-Lived, Tick-Bound Memoization in JavaScript Sometimes, typical memoization function won't cut it when there are so many changing variables in play between ticks of the event loop. Let's explore how we might fine-tune it.

I wrote about using short-lived memoization bound to a single tick of the event loop in JavaScript. queueMicrotask() is awesome. Read:

macarthur.me/posts/memoiz...

14.01.2025 15:41 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Using Forced Reflows, the Event Loop, and the Repaint Cycle to Slide Open a Box Triggering smooth, reliable CSS transitions with JavaScript can be weirdly more complicated than you expect. We're gonna explore it more.

I blabbed a ton about forced DOM reflows, the event loop, and the browser’s repaint cycle, just to slide open a box with CSS transitions & JavaScript. Look:

macarthur.me/posts/box

06.01.2025 19:20 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Comment submissions for JamComments just got a big speed boost because I finally remembered to set Laravel’s QUEUE_CONNECTION to something other than β€œsync.” πŸ€¦β€β™‚οΈ

05.12.2024 13:34 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
You Might As Well Use a Content Security Policy Content Security Policies, even for simple, content-focused sites, offer good protection against rare but real vulnerabilities out there. You might as well just get one.

I’ve been learning about content security policies and have reached the following conclusion:

They’re valuable even for simple blogs and very easy to set up. You should probably just get one.

macarthur.me/posts/csp

02.12.2024 18:28 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

My first (personal) M series MacBook is coming this week. I’ve been doing all dev work on a 2015 MBP until now and I’m so ready to enter the future.

02.12.2024 14:19 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Simple demo for embedding JamComments client-side:

- ~10 lines of code to configure
- no custom styles necessary
- ~2.6kb (gzipped) of JavaScript needed to load
- ~3.6kb of HTML to load lazily load in after that

And none of the grossness other comment tools throw in.

jamcomments.com/demo/vanilla

01.12.2024 02:49 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
Let the Bin Buddies roll out your bins for you! We'll take out your trash & recycling bins for you every week, so you don't have to keep forgetting about it!

My daughters are starting their first entrepreneurial endeavor. Introducing the Bin Buddies!

binbuddies.pro

30.11.2024 00:00 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Vanilla JavaScript

You can now embed comments on your website entirely client-side. Very similar to how some other services work, but with a waaaaaaaaaay smaller performance penalty and far less grossness.

jamcomments.com/docs/integra...

29.11.2024 21:12 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
JamComments: A guilt-free comment service for your blog. A blog comment service and Disqus alternative that won't leave you feeling like you missed a shower.

JamComments.com is about to become very CSP-friendly. And as a result, it’ll be very difficult to tell you’re using a third-party service, even by looking through the page source. πŸ₯·

24.11.2024 00:20 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Crazy how we’ve all just forgotten about the fact that there’s a map on the back of the Declaration of Independence.

22.11.2024 23:26 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

@macarthur.me is following 20 prominent accounts