Search code examples
javascripthttpshref

href google fonts over https only if https page requested


I am using google fonts on webpage, but the font is being called over http -

    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>

If the page is requested over https - the fonts are identified as unsecure content.

How do I request

<link href='https://fonts.googleapis.com/css

only if the page is being requested over https connection, and serve http if http requested?


Solution

  • drop the http: which will make the url relative to the current scheme

    <link href='//fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>