Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 27, 2021 06:42 am GMT

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.

Buy Me A Coffee

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

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To