Posted on:
Categories: SharePoint;Office 365

​If you look at an out-of-the-box display template like Item_TwoLines.html, you will notice ~sitecollection, a sharepoint token that gets replaced by the site collection url during rendering. 

$includeLanguageScript(this.url, "~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/CustomStrings.js");

 It is best practice to use site collection token because you cannot assume site collection always start at the root. You can do something similar with CSS by using includeCSS

$includeCSS(this.url, "~sitecollection/Style Library/MyCompany/Styles/global.css");
You can also use replaceUrlTokens like
var imagePath = Srch.U.replaceUrlTokens("~sitecollection/Style%20Library/MyCompany/Images/");