An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
HTML : Using a protocol-independent absolute path
If the browser is viewing an page in SSL through HTTPS, then it'll request that asset with the https protocol, otherwise it'll request it with HTTP.
This prevents that awful "This Page Contains Both Secure and Non-Secure Items" error message in browsers, keeping all your asset requests within the same protocol.
Let's understand this with an example -
Example 1 -
For Website URL - http://RajeshKumarYadav.com
<img src="http://RajeshKumarYadav.com/img/logo.png"/>
will be fine but
<img src="https://RajeshKumarYadav.com/img/logo.png"/>
will through error.
Example 2 -
For Website URL - https://RajeshKumarYadav.com
<img src="https://RajeshKumarYadav.com/img/logo.png"/>
will be fine but
<img src="http://RajeshKumarYadav.com/img/logo.png"/>
will through error.
What's the fix then?
To fix the error, we should avoid writing protocol as http
or https
and we can call the assets as mentioned below -
<img src="//domain.com/img/logo.png"/>
Here you can see we are using //
only and if your website has http then image will also have http
automatically, if your website has https
in the URL then image will automatically have https.
With all that being said, I highly recommend you keep learning!
Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.
Original Link: https://dev.to/rajeshkumaryadavdotcom/html-using-a-protocol-independent-absolute-path-3oa1
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To