Looking for a site's URL information, then the window.location object is for you! Use its properties to get information on the current page addre...
For further actions, you may consider blocking this person and/or reporting abuse
Great article but I found an error
on
Here's the complete list of properties that you can change:
// Example
.hostname and .host should be swaped
take care, Renas
AH yikes 😱 Let me fix that now!! Great catch! Thanks for letting me know 😰
Can you follow me back if posible?
Good to know. I think I'm starting to understand how dev.to work and why it is so fast (hover on link => make request and store result in cache, click on link = assign url and load cached content).
I may implement those tricks to enhance user experience on my websites :)
woooo, would love to see the inner working of how dev.to works 🤩
It's Preact. You can find source code on GitHub.
We use InstantClick for that "hover on link => make a request" effect :) instantclick.io/
Loading cached content is mostly because of Fastly!
Most of the pages are Rails pages, and there's some Preact mixed in every once in a while.
Don't really know how caching is managed or anything about the Rail framework, but instanclick seems to be a gold nugget!
Thanks for the link, and bravo for this insanely fast website :)
Heads up: root URLs always end with slash. More specifically, the
path
part that follows host and port is mandatory and according URL format specification cannot be blank nor omitted and must start with slash, so the shortest value usually denoting root path is just '/'. Most agents tend to fix invalid input and silently add missing parts of URL before making request, and some user agents tend to hide single slash of root paths for (dubiously) aesthetic reasons, but actual HTTP request such agent produces always involves/
path. "URLs" likehttp://host
,http://host?search
,http://host#hash
are all in fact invalid and should be expressed ashttp://host/
,http://host/?search
,http://host/#hash
.url.spec.whatwg.org/#concept-url-path
url.spec.whatwg.org/#path-absolute...
This is fabulous
Thanks Ben! 😄
When I was trying to decide an efficient way to determine if files were being served on
localhost
or prod, I came here and ended up withif(window.location.port)
to test for localhost 🙌I'm sure I will visit more in the future, great job creating an excellent, clear resource!Nice! Glad you found the article helping and you were able to apply the knowledge right away! I also list all my tidbits on my site if you want another resource to check out 😊 > samanthaming.com/
I often use
new URL(location.href).searchParams
, BTW. Much more powerful thanlocation.search
.OH COOL! must be a new-ish web API, no support for IE ... hmm...did they create this to hopefully replace window.location 🤔
I'll need to look into it, maybe for a future tidbit 😊
Wonderful, thanks for the breakdown :)
You're very welcome! Thanks for reading 😄
Awesome!
Thank you! 🙂
brilliant break down! really filled in the gaps for me. 🙌
awesome, glad to hear that! Thanks for reading my article 😊
This is a great Post!
I learned something thanks 💯
Thanks Mustapha! So glad this post was helpful for you 👏
You're so good at explaining this stuff to other developers, Samantha! I learned a bunch of things from reading.
Thank you Eric! Being able to explain and communicate where other people can understand is a skill I'm trying to get better at. So I'm glad to hear I'm doing okay 😆 -- there's still more room for improvement! I'll keep practicing -- hopefully one day i can explain it where non-dev will also understand it and they will be encouraged to learn programming 😊
Thanks for this well-organized post!
Nice guide for a consultation
Hi! Great article!
On the first example (samanthaming.com/tidbits/?filter=JS#2), window.location.href would return the entire URL.
ah yikes! great catch, let me fix it 😱 Thanks for letting me know 😨
Thank you so much for taking your time and effort to write this article AND adding a beautiful infographic ♥️
Glad you enjoyed the image and article! that's a double success, thanks for the positive feedback 😊