Redirect HTTP links to HTTPS with Javascript What is the shortest way to secure a site with Javascript?
I am new to Code Golfing, and this is what I've come up with so far. I bet that this could be improved though:
Challenge:

Make a script which redirects http:// to https:// with the least bytes of code

Attempts:
Original code (150ish BYTES!):
if (window.location.protocol != &quot;https:&quot;) {
  window.location.href =
    &quot;https:&quot; + window.location.href.substring(window.location.protocol.length);
}

My code so far (68 bytes):
var l=location;':'==l.protocol[4]&amp;&amp;(l.href=l.href.replace(':','s:'))

Updated, thanks to @mypronounismonicareinstate (52 bytes):
l=location;l[&quot;protocol&quot;][5]||(l[&quot;protocol&quot;]=&quot;https&quot;)

Thanks to @arnauld (45 bytes):
(l=location)[p='protocol'][5]||(l[p]='https')

This works, thanks to @anderskaseorg (38 bytes):
with(location)protocol='https'+href[4]

However, this last answer would not be commonly used on a real site
Could this be minified more?
39 38 bytes

with(location)protocol='https'+href[4]

How it works

If location.href starts with http:, this assigns location.protocol = 'https:'.
If location.href starts with https:, this assigns location.protocol = 'httpss'.  According to the specification, this should have no effect because httpss is neither http nor https.  Firefox obeys this specification.  Chrome seems to try to find an external app to open the httpss scheme (bug).