r/javascript • u/supercohost • 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()
11
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
0
Feb 03 '19
[deleted]
27
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
Feb 03 '19
[deleted]
3
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
6
Feb 03 '19
What kind of theme is that ? Looks smooth
0
Feb 03 '19
[deleted]
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.
FAQs Custom Your Reminders Feedback Code Browser Extensions
4
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
dataattributes 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
-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.
2
u/nerdbeere Feb 03 '19
1
u/sneakpeekbot Feb 03 '19
Here's a sneak peek of /r/webdev using the top posts of the year!
#1: Animated login avatar | 88 comments
#2: StackOverflow is super toxic for newer developers
#3: Markup horrors of the ad blocker wars | 403 commentsI'm a bot, beep boop | Downvote to remove | Contact ^^me | ^^Info | ^^Opt-out
0
0
-1
119
u/voidvector Feb 03 '19
Feels like this is a feature that's going to be abused by ads