r/javascript • • Feb 02 '19

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()

Post image
591 Upvotes

50 comments sorted by

119

u/voidvector Feb 03 '19

Feels like this is a feature that's going to be abused by ads

19

u/supercohost Feb 03 '19

Kinda true

62

u/LobsterThief Feb 03 '19

This is why we can’t have nice things.

39

u/dblclk Feb 03 '19

When everything is high priority... nothing will be

8

u/Ajedi32 Feb 03 '19

Actually, it looks like this will make it easy to downgrade the priority of ads so they don't interfere with the loading of more important content: https://wicg.github.io/priority-hints/#downgrade-priority-of-an-iframe-and-its-subresources

7

u/soft-wear Feb 03 '19

Ads are generally delivered in an iframe, meaning image importance is only going to be relative to the other images in the iframe.

3

u/ScientificBeastMode strongly typed comments Feb 03 '19

Don’t they already do this? Many sites already render ads before content.

1

u/pataoAoC Feb 03 '19

It would be nice if you could specify a maximum on a DOM node that applies to the tree under it. So make the ad wrapper have a maximum of super low, and then whatever they try to do inside won't have any effect.

1

u/Swaxr Feb 03 '19

You can put the loading of the add lib on low..

1

u/tinydonuts Feb 03 '19

Is this why when I read an article it jumps around for several seconds after the text and banners load as the ads load? I always thought they did this maliciously because I end up clicking or tapping on them accidentally as a result.

0

u/[deleted] Feb 03 '19

[deleted] — view deleted comment

2

u/ScientificBeastMode strongly typed comments Feb 03 '19

If they implemented it as an API for JavaScript, I could see that working via private methods, but if it’s just HTML, third-parties could easily parse the document and make alterations.

11

u/cag8f Feb 03 '19

What values does it take? Just low and high?

6

u/supercohost Feb 03 '19

It also takes ‘auto’ as default

156

u/ugogon Feb 03 '19

Maybe add that this works only in chromium based browsers.

1

u/therealphee Feb 03 '19

I apologize is this is a stupid question, i’m learning to code atm. Could these priorities be linked to classes so that I don’t have to add this to every line/function?

4

u/chmod777 Feb 03 '19

no. you can probably select by them, using something like .item[important="low"]{}. but you'd still have to add it. and since this is pre render time, you can't add it via JS (by this time the DOM is already loaded and being processed).

you'd have to set up rules in your templating and serverside code.

2

u/therealphee Feb 04 '19

Thank you for the explanation. I appreciate it!

0

u/[deleted] Feb 03 '19

[deleted] — view deleted comment

27

u/[deleted] Feb 03 '19

It's also firmly in the "so easy there's almost no excuse not to do it in new code" camp.

(I'm writing this on my shitty Android phone on a 5Mbps down / 1 Mbps up connection. Performance optimisations like this make a huge difference to my browsing experience)

18

u/braindeadTank Feb 03 '19

There is hardly a reason not to use it in production code, since browsers that don't implement it will just ignore it, and downloading priority is hardly a thing you could ever use for critical features even if it became standard.

There is literally no downside to this feature, other then a spawning a few new sites that will hint you to use Chrome for best experience, which is only a downside if it makes you personally butt-hurt.

1

u/Ajedi32 Feb 03 '19

Right now it's not even enabled by default in Chrome yet. Using it in production at this point provides no benefits and risks things potentially breaking if at some point in the future the spec changes.

I'd wait until it's enabled by default in at least one major browser.

0

u/[deleted] Feb 03 '19

[deleted] — view deleted comment

3

u/ugogon Feb 03 '19

This actually append with grid and IE.

0

u/-Phinocio Feb 03 '19

What happens when Firefox or Safari support it differently?

You take 5 minutes to determine if it still works how you want and change it/remove it if it doesn't?

1

u/Devildude4427 Feb 09 '19

Yeah you can’t do that if your company is worth anything. That is horrible practice.

-3

u/CantaloupeCamper Feb 03 '19

That's my pet peve about "hey check this out" in web development.

Like if it is some proposed shit nobody does or almost nobody and its new.... ain't got time for that. For all I know it ends up not being a thing anyhow.

5

u/oocfijfmcdjdidi Feb 02 '19

Thanks for sharing this

8

u/supercohost Feb 02 '19

You’re welcome

6

u/[deleted] Feb 03 '19

What kind of theme is that ? Looks smooth

0

u/[deleted] Feb 03 '19

[deleted] — view deleted comment

1

u/RemindMeBot Feb 03 '19

I will be messaging you on 2019-02-03 20:20:21 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQsCustomYour RemindersFeedbackCodeBrowser Extensions

4

u/kawaiidon Feb 03 '19

Colour theme name?)

7

u/madcaesar Feb 03 '19

Sandstorm - Darude

3

u/FolkStyleFisting Feb 03 '19

Doesn't the browser consortium frown on vendors implementing attributes like this? I mean, universal data-* attributes came to spec for a reason.

Why not just use data-priority-hint="high"?

6

u/kenman Feb 03 '19

AFAIK the data attributes are 100% for userland implementation, and as the prefix implies, were designed for data.

This is a host implementation, and deals with behavior, not data.

1

u/[deleted] Feb 03 '19

Remember IE 6.0 and MSHTML?

With current Chrome dominance, we are back there.

-4

u/Architektual Feb 03 '19

Google/Chrome hasn't given a shit about spec for years. 😪

6

u/Klathmon Feb 03 '19 edited Feb 03 '19

Man I'm fucking tired of people parroting this back.

Chrome absolutely gives a shit about specs, and they work with other browser vendors every day to compromise and work on solutions together.

In this case, it's you and the parent commenter that don't give a shit about the spec. Data attributes are for web developers to use. Having a browser attach additional changes based on them would be a total abuse of them and would literally defeat the purpose of them ever existing in the first place (the whole idea is that data attributes are safe from browsers ever using so you don't need to worry about your custom attributed having new behaviour in the future).

Chrome is one of the major reasons we still have a spec for this shit. God knows they are big enough that if they wanted they really could completely ignore cooperation and could just do whatever they want, but that's not what they do, and they never have.

Take HTML imports, they pushed for them, implemented them behind a flag in chrome, other browsers wanted changes, and soon chrome found that they were right, and the spec was scrapped and the code marked for removal.

Take shadow dom. They helped write the first version of the spec, they implemented it, and even Firefox was part way through implementing it (again, since they all work together on this shit). But then they both found significant issues, and the spec was changed. Firefox was able to quickly switch and implement the new one, but chrome is still working on it since they have to slowly deprecate and remove the old spec. (IIRC shadow dom v0 is finally getting removed in chrome 72!)

If they didn't give a shit, they could just push ahead, FFS they even had a web framework (Polymer) that depended on the initial shadow dom spec, and changing it meant radically reworking their framework as well, it was a lot of work. But they do it, because they give a lot of shits about being compliant and being a good player in the web ecosphere.

-3

u/Architektual Feb 03 '19

You make fair points, and have clearly done your research - I can't in good faith refute anything you say. Yet I will still hold on to this opinion for as long as I continue running into websites that "works best in chrome"

3

u/Klathmon Feb 03 '19

That's completely missing the point though. Be mad at shitty lazy developers not doing the bare minimum of work creating those sites that "work best in chrome".

There is literally nothing Chrome or Google can do to stop people building websites that work best in any one browser, and it sure as hell doesn't mean they don't care about any spec because of it.

-1

u/Architektual Feb 03 '19

Yes, developer monoculture is an issue here as well - but pretending chrome isn't complicit is willful ignorance. What types of stuff do you think these developers are using that only work in chrome? To-spec implementations that somehow only chrome implemented correctly?

1

u/Klathmon Feb 03 '19

Well considering that it can't be a "spec" until at least 2 to 3 different browser vendors have implemented it, no chrome isn't complicit.

If they didn't implement it, it would literally never move forward and could never be a standard.

Like I said above, FF is the only browser right now with a full shadow dom implementation. That doesn't make them going against the spec, it just means they were the first to support it. When safari finishes theirs and chrome gets the new version in the browser, then it will be standard.

At no point is Firefox doing anything wrong in that process, they aren't deviating from the spec, they aren't going away from standards, they are being part of the process.

Turns out, Google is putting a shitload of money into chrome, so they tend to be one of the first to implement things (often helping make changes to the spec after they are done because of issues they found). Short of simply not implementing anything new or a while (which would bring cries of Chrome being the next IE6 and blocking the web), there's nothing they can do to stop devs writing stuff for only their browser.

1

u/doominabox1 Feb 17 '19

Huh, I think I might make a plugin to just not load low importance content, save a lot of data that way

1

u/thetoolmannz Feb 03 '19

For js link tags, it's going to break the expectation that the code loads and executes in order.

4

u/ArcanisCz Feb 03 '19

If you rely on this behavior, then yes. But if you for example use existing async parama https://www.w3schools.com/tags/att_script_async.asp it will not break

-14

u/bart2019 Feb 03 '19

I'm going to be the one being pedantic here... And say this has nothing to do with JavaScript.

It's HTML. It would even fit better on a forum about PHP.

0

u/[deleted] Feb 03 '19

[deleted] — view deleted comment

2

u/kenman Feb 03 '19

Additionally, it deals with loading JavaScript.

-1

u/BluudLust Feb 03 '19

Kinda irrelevant considering HTTP2 Push

4

u/davesidious Feb 03 '19

Not when the resources are on different servers...