I think I've solved a difficult thing to do in Svelte:
Doing an idempotent load of an external javascript. That means it's actually loaded only once, no extra tags are inject, but your callback onLoad code still runs each time.
Why do you need this?
The first reason is that a *lot* of performance measurements that Google will use to penalize you (but not their own apps) involves page load speed and the size of downloads. If you import JS code that's massive into your SPA it'll penalize you, but not if you load it as needed.
This makes sense in a lot of ways. If your main app loads very fast because it's small, then people will put up with slower load times on pages that need big .js files. In my case, WebTorrent is a massive pig, but I only use it on Video pages, so just load it on those pages.
But, svelte has a couple of broken tags that are supposed to help.
<svelte:head> can add CSS and JS links, but *every* component that loads those. If you have 10 instances of the same component you'll get 10 <script> or <link> tags added, and that means 10 HTTP or cache hits.
I find this to be a bug since 90% of the time I never want the head to be repeated over and over every time that component is rendered. I want it to render ONE <svelte:head> and possibly update it, no matter how many components I load on the page.
So this component basically does this with javascript you want to load by tracking what's already been loaded and then simply not doing it again. It seems to solve most timing issues, but I'll probably run into some odd corner cases later.
What's the other reason you need it?
Some APIs like Paypal's have you dynamically construct a JavaScript URL that they serve you. You can't put those in a <svelte:head>, and if you did it'd constantly load that over and over. Instead you need to manually call the inject_remote function there after you get the URL.
We could argue all day long about how stupid Paypal is, but it comes up quite often (probably because Paypal is worth billions so copying them makes your VCs who are Paypal's board happy), so it's something you need to do. This at least helps make sure you aren't double loading.
I had inject_remote before but I hadn't figured out how to generalize making it idempotent. Now I have the <Script> component that does a good enough job at replacing <script src=""> inside Svelte and keeping it all straight, while also providing the inject_remote function.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Let's take a moment to look at how people demanding "technology" be me humane weirdly only focus on programmers and exclude designers--the real party to blame for the attention economy--by looking at the content from:
The site's goal is to "catalyze a more humane future", which is actually a great thing, but by focusing entirely on programmers, managers, and CEOs they exclude designers. This is done because design is categorized as "art" and art is considered a "humanity" in American culture.
Artists are viewed as sort of a religious class, and in American culture criticizing the Church and religious figures is considered wrong. Even if someone isn't Christian, you'll find some religious figure they consider an authority you can't criticize. Art is that authority.
A cultural observation about intellectuals is how much they actually hate intellectual pursuits. They worship intellectual prowess while at the same time scoffing at anyone who has to study, but studying the world is the *foundation* of intellectualism.
That's why you'll see people who want to learn a subject "naturally" without actually studying the subject. They want it to magically flow into their being so they can be intelligent without being "tainted" by study of the topic. They want to gain skill without direct study.
These are the people who throw books at kids to teach them reading, but don't actually teach them how to sound out the bizarre English alphabet. They're the people who want to teach music with "just make them jam in a social context" without teaching them notes and chords.
A few people have asked what the impact of Amazon controlling Rust could be to the language? Surely Amazon wouldn't kill off the language since they're using it, and Rust is pretty solid now so what could Amazon possibly do?
Let's look at some history in similar situations:
XML - Microsoft bought people on the XML steering committee and famously steered it in a direction that supported *their* Enterprise ambitions like SOAP. Any feature that threatened to give another company an advantage or *cost them money* was probably fought.
JavaScript -- Netscape was famous for being written in this weirdo XML/XUL/C++/JavaScript monstrosity code base, so it's no wonder that while Netscape dominated the internet JavaScript stagnated. Any feature that cost Mozilla money updating XUL was shut down.
Given my recent Arch Linux debacle I think I should cover a few persistent FLOSS vs. Commercial software myths. These are usually put forward as some kind of defense when leaders of a FLOSS project screw over their users without consent.
#1) Commercial Whataboutism
"Commercial companies screw people over too. Why do FLOSS projects have to not screw people over?!"
That's whataboutism, and more importantly authoritarian whataboustism. I say there's two kinds of whataboutism:
You have whataboutism that is pointing out a bias that people in positions of authority have:
"Why do you punish this kind of person more than that kind?"
Then there's what I call Authoritarian Whataboutism:
"I'm allowed to harm that person because that other guy does too."
Oh I hate myself right now. I wrote all this code for learnjsthehardway.com before I had to stop because Sapper died and it wouldn't work for students.
Now I'm trying to bring over the good stuff and I'm on WebTorrent...and it's a nightmare. I have no idea what I wrote.
I may have to just sit down for two days and re-read all the old code, but I just want to get WT working. I'm trying to load the JSON data I generate, and for some reason I can't figure out where I generate this one torrent hash. I scour all of my code, I can't find it.
That's because I'm *not* generating it. I'm just writing it in a header of the .md files like a loser. LOL. I think I was manually making these hashes to get going and planned on generating them but never got around to it.
Alright, this is a *glorious* bug in Firefox and Chrome but not Safari.
The Scene: In my webapp I can type ctrl-alt-b to get the "bandolier". It's a dev tools/admin panel. This works just fine in safari, but fails in Firefox and Chrome on OSX only.
The code, with a log:
Now, safari reports the following when I press some keys:
But, Firefox and Chrome report *this* when I do the same keys. See that ∫ there?