Over a million developers have joined DZone.

SharePoint and protocol-relative URL's

DZone 's Guide to

SharePoint and protocol-relative URL's

· ·
Free Resource

Introduction to protocol-relative URLs

Recently I learned an amazing new trick, the protocol-relative URL, where the scheme of a URL (the http bit) can be dropped and your browser will use the same scheme that the page’s URL uses. This is very useful for when you have a website on http & https. For example you can set an image URL to be:


and if you browse to


then it will load the image from


but if you got to


then it will load the image from

https://demo.com/horse.png – and this works with CSS & JavaScript too!

This is not some odd browser trick, this is in the standard for how URLs work!

To be clear this is similar, but not the same as absolute & relative URLs.


SharePoint (and for this post, this has only been checked with 2010 so your mileage may vary on newer/older versions) does not follow this standard and actually breaks protocol-relative URL’s in two ways.

Front End

If you are working on the SharePoint UI and putting content in a content editor web part or an text column in a list and you edit the HTML and put in a protocol-relative URL SharePoint and hit save SharePoint will “fix” it by putting the current scheme in for you! So no matter what you do, on the front end you are completely stuffed.


You put in <img src=”//sharepoint/horse.png”/> SharePoint will change it to <img src=”http://sharepoint/horse.png”/> (assuming your page is on a http scheme).

Back End

The other scenario is you are working with the SharePoint web services, for example the list service, and setting the HTML that way – SharePoint once again will try and “fix” things. Interesting it does something completely different to the front end. I guess the front end uses JavaScript and the back end uses some other code. It removes the attribute completely from the HTML.


You put in <img src=”//sharepoint/horse.png”/> SharePoint will change it to <img /> – yip the src attribute is gone.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}