5 ms·
Ok, I'll bite - how else do people do this? (Speaking as someone who has ONLY ever done it this way.)
by dmd 4y ago
Ok, I'll bite - how else do people do this? (Speaking as someone who has ONLY ever done it this way.)
- scarface74 4y agoMost of the time it’s via a server redirect or a rule on the load balancer.
- teh_klev 4y agoOk, how does the server or the load balancer know if scripting is enabled on the first request?
- scarface74 4y agoThe 30x redirect status codes are handle by the browser whether or not scripting is enabled. It is part of the http standard. https://www.rfc-editor.org/rfc/rfc9110#status.301 https://www.rfc-editor.org/rfc/rfc9110#status.301
- teh_klev 4y agoI know this, please read my comment here: https://news.ycombinator.com/item?id=35675861 https://news.ycombinator.com/item?id=35675861
- ssttoo 4y agoThe most common is using an HTTP header. Less common: `document.location` in JavaScript https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirectio...
- tantalor 4y agoThat wouldn't work in a noscript
- teh_klev 4y agoNot sure why you're being downvoted. Many of the sibling comments are referring to server side generated HTTP 302 headers, and server side (without lots of fancy shenanigans) you won't know (server side) if the client has disabled scripting on the first page hit. And document.location is pointless if the client has turned off scripting.
- aendruk 4y agoDifferent readings of the initial question: A) “how do people redirect”, to which the point about noscript sounds like irrelevant whining B) “how do people redirect only visitors who don’t have scripting” to which most of the answers are trivially wrong
- feeela 4y agoTherefore the method called "progressive enhancement" might be an option to start with an HTML-only variant and load JS only if available and required for the current page.
- jdlshore 4y agoHTTP 3xx status code with a Location header.
- riffic 4y agoone way it's not done is with DNS
- justsomehnguy 4y agoWell... Serve a "shitty" page by default, redirect with JS to "enriched" page. Or tinker with server configuration to depend on 'Host: nojs.plz.fqdn'.
- teh_klev 4y agoThe noscript tag is the correct way to do this. Server side, when you first generate page content you have no idea if the client has scripting enabled, which is why you include a noscript element to advise the user what to do, or redirect them using a meta tag inside the noscript element. So all these suggestions below to use server side generated HTTP headers and 302 (or 301) redirects are incorrect...because you won't know, on the first page hit, if the client has scripting enabled. At this point in time only the client knows if scripting is available. Also browser capability sniffing based on headers sent from the client in the first request is not reliable. For more info see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript https://developer.mozilla.org/en-US/docs/Web/HTML/Element/no...
- deleted 4y ago[deleted]
- JimDabell 4y ago> So all these suggestions below to use server side generated HTTP headers and 302 (or 301) redirects are incorrect...because you won't know, on the first page hit, if the client has scripting enabled. Perhaps I’m misunderstanding you, but do you think that the HTTP approach only works when JavaScript is enabled? That isn’t the case. Go ahead and use HTTP 3xx responses; they work in all cases. Don’t use the <meta> element or the <noscript> element. Just redirect with HTTP. If you try to use HTML for this, you’ll be serving up 200 OK responses and things that understand HTTP but not HTML won’t understand there’s a redirect.
- teh_klev 4y agoOk, in the context of the article, what I'm saying is when a browser requests a page for the very first time, the server will have no idea if scripting is enabled and so your server side code will have no idea whether to send a 302 redirect to your no-script content. This is why the noscript tag exists and should be used. Yes I'm aware there are various sniffing techniques you could use to work out if scripting is enabled but these are not always reliable. Only the browser knows authoritatively if scripting is available and hence you should use the noscript element to respond to clients that disabled scripting.