Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Web Fonts on HTTPS pages on Chrome

Tags:

https

fonts

I'm working on an ecommmerce project. Parts of the site are HTTP by default. Others, such as the checkout page, are HTTPS by default. On the HTTPS pages I'm getting this message on the console on Chrome:

[blocked] The page at https://store-ws3q9h.mybigcommerce.com/checkout.php?tk=c99fa39e007db6376dcddaac68695c22 ran insecure content from http://fonts.googleapis.com/css?family=PT+Sans. 
[blocked] The page at https://store-ws3q9h.mybigcommerce.com/checkout.php?tk=c99fa39e007db6376dcddaac68695c22 ran insecure content from http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700.
[blocked] The page at https://store-ws3q9h.mybigcommerce.com/checkout.php?tk=c99fa39e007db6376dcddaac68695c22 ran insecure content from http://fonts.googleapis.com/css?family=Patua+One.

The fonts are linked on the document head in this way:

<link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Patua+One' rel='stylesheet' type='text/css'>

It looks ok on other browsers I have tested so far.

like image 639
Jack Pilowsky Avatar asked Aug 02 '13 22:08

Jack Pilowsky


People also ask

What is https font Google?

Google Fonts is a library of 1,429 open source font families and APIs for convenient use via CSS and Android. The library also has delightful and beautifully crafted icons for common actions and items. Download them for use in your digital products for Android, iOS, and web. Fonts.

How do I add fonts from Google Fonts to HTML?

To add google fonts, search for the google fonts, select the font category and family, then select the font style of your choice. Once you select the font, “copy the font link”, from the “selected families windows” and paste it in the head section of the HTML file.


2 Answers

Create a schema agnostic url

Change http://fonts.google... to //fonts.google...

Drop the http: or https: from the front, the browser will use whichever schema you're currently using on the site.

You may request resources using https from http, but not the other way round. An alternative to the above solution (and probably best practice) is to just always use https if it's available (which it must be if you're using this style of link, otherwise there no point in it anyway).

like image 110
Lee Avatar answered Oct 23 '22 21:10

Lee


Remove the protocol from your URL and let the browser determine it:

<link href="//fonts.googleapis.com/css?family=PT+Sans" ...

If your page is HTTPS, the font will be loaded from the HTTPS URL. If the page is HTTP, it'll be loaded from the HTTP URL.

like image 29
Blender Avatar answered Oct 23 '22 23:10

Blender