Modern solution to these issues is having SRV record on appropriate protocol sub-domain which AFAIK (and somewhat surprisingly) is honored by most modern browsers.
Browsers don't use SRV records for HTTP. With them one wouldn't need www subdomain CNAME hacks.