Including Google Web Fonts link or import?












149















What is the preferred way of including Google Web Fonts to a page?





  1. via the link tag?



    <link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>



  2. via import in a stylesheet?



    @import url(http://fonts.googleapis.com/css?family=Kameron:400,700);



  3. or use the web font loader



    https://developers.google.com/webfonts/docs/webfont_loader












share|improve this question

























  • You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

    – Obmerk Kronen
    Jun 5 '16 at 21:11
















149















What is the preferred way of including Google Web Fonts to a page?





  1. via the link tag?



    <link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>



  2. via import in a stylesheet?



    @import url(http://fonts.googleapis.com/css?family=Kameron:400,700);



  3. or use the web font loader



    https://developers.google.com/webfonts/docs/webfont_loader












share|improve this question

























  • You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

    – Obmerk Kronen
    Jun 5 '16 at 21:11














149












149








149


48






What is the preferred way of including Google Web Fonts to a page?





  1. via the link tag?



    <link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>



  2. via import in a stylesheet?



    @import url(http://fonts.googleapis.com/css?family=Kameron:400,700);



  3. or use the web font loader



    https://developers.google.com/webfonts/docs/webfont_loader












share|improve this question
















What is the preferred way of including Google Web Fonts to a page?





  1. via the link tag?



    <link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>



  2. via import in a stylesheet?



    @import url(http://fonts.googleapis.com/css?family=Kameron:400,700);



  3. or use the web font loader



    https://developers.google.com/webfonts/docs/webfont_loader









fonts webfonts google-webfonts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 3 '17 at 11:44









linusg

4,29141843




4,29141843










asked Sep 7 '12 at 10:41









kajokajo

3,20642628




3,20642628













  • You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

    – Obmerk Kronen
    Jun 5 '16 at 21:11



















  • You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

    – Obmerk Kronen
    Jun 5 '16 at 21:11

















You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

– Obmerk Kronen
Jun 5 '16 at 21:11





You might also want to read this question before using google fonts at all . depending on the specific project - it might not always be the smart choice .

– Obmerk Kronen
Jun 5 '16 at 21:11












2 Answers
2






active

oldest

votes


















241





+200









For 90%+ of the cases you likely want the <link> tag. As a rule of thumb, you want to avoid @import rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.



Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.



Once again, the 90% case is the <link> tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.



For more info, and an in-depth look at Google Web Fonts, check out this GDL video






share|improve this answer


























  • "because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

    – Alex
    Jul 15 '14 at 10:53











  • The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

    – rvighne
    Jul 21 '14 at 0:05






  • 10





    This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

    – Gal
    Apr 20 '15 at 4:38






  • 2





    Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

    – James Cushing
    Oct 20 '15 at 13:34





















-1














You can save some request time



...if you take some extra coding time.



It's really no big deal, just open Google's simplified one-line link:



   http://fonts.googleapis.com/css?family=Kameron:400,700


and see what it gives you:



/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 400;
src: local('Kameron'), url(https://fonts.gstatic.com/s/kameron/v8/vm82dR7vXErQxuzngLk6Lg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 700;
src: local('Kameron Bold'), local('Kameron-Bold'), url(https://fonts.gstatic.com/s/kameron/v8/vm8zdR7vXErQxuzniAIfO-rpfQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


Yes, that's only a couple of other requests. It's faster to start with these directly - even faster if you download the font files to your own server and add a localhost URL before the Google ones. I know I know, we like CDNs and paralell requests, they are meant to be faster - but just try and see for yourself.



Now for the original question: don't @import, don't <link>, just put this code right into your existing global CSS, it's the best for your server. It needs no plus request, it's not a separate move - only a very slight increase in the size of the file which will add practically nothing to a request's processing time. Will it be beautiful to look at? No... But your site will hopefully get a lot more requests than revisions :) So help the server, not yourself.



Overall, I think it's worth the extra mile.



The one-line version is not designed to be efficient but simple - for bloggers who want the easiest possible way. You know better.






share|improve this answer





















  • 3





    Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

    – Punit S
    Nov 29 '18 at 11:45











  • @PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

    – dkellner
    Nov 29 '18 at 16:18














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12316501%2fincluding-google-web-fonts-link-or-import%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









241





+200









For 90%+ of the cases you likely want the <link> tag. As a rule of thumb, you want to avoid @import rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.



Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.



Once again, the 90% case is the <link> tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.



For more info, and an in-depth look at Google Web Fonts, check out this GDL video






share|improve this answer


























  • "because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

    – Alex
    Jul 15 '14 at 10:53











  • The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

    – rvighne
    Jul 21 '14 at 0:05






  • 10





    This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

    – Gal
    Apr 20 '15 at 4:38






  • 2





    Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

    – James Cushing
    Oct 20 '15 at 13:34


















241





+200









For 90%+ of the cases you likely want the <link> tag. As a rule of thumb, you want to avoid @import rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.



Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.



Once again, the 90% case is the <link> tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.



For more info, and an in-depth look at Google Web Fonts, check out this GDL video






share|improve this answer


























  • "because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

    – Alex
    Jul 15 '14 at 10:53











  • The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

    – rvighne
    Jul 21 '14 at 0:05






  • 10





    This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

    – Gal
    Apr 20 '15 at 4:38






  • 2





    Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

    – James Cushing
    Oct 20 '15 at 13:34
















241





+200







241





+200



241




+200





For 90%+ of the cases you likely want the <link> tag. As a rule of thumb, you want to avoid @import rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.



Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.



Once again, the 90% case is the <link> tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.



For more info, and an in-depth look at Google Web Fonts, check out this GDL video






share|improve this answer















For 90%+ of the cases you likely want the <link> tag. As a rule of thumb, you want to avoid @import rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with web fonts: dynamic providers like Google WebFonts serve platform-specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.



Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.



Once again, the 90% case is the <link> tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.



For more info, and an in-depth look at Google Web Fonts, check out this GDL video







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 15:14









Sayed Mohd Ali

1,5242520




1,5242520










answered Sep 12 '12 at 1:12









igrigorikigrigorik

7,34322328




7,34322328













  • "because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

    – Alex
    Jul 15 '14 at 10:53











  • The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

    – rvighne
    Jul 21 '14 at 0:05






  • 10





    This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

    – Gal
    Apr 20 '15 at 4:38






  • 2





    Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

    – James Cushing
    Oct 20 '15 at 13:34





















  • "because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

    – Alex
    Jul 15 '14 at 10:53











  • The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

    – rvighne
    Jul 21 '14 at 0:05






  • 10





    This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

    – Gal
    Apr 20 '15 at 4:38






  • 2





    Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

    – James Cushing
    Oct 20 '15 at 13:34



















"because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

– Alex
Jul 15 '14 at 10:53





"because they defer the loading of the included resource until the file is fetched" - isn't that a good reason to use @import? Because normally you don't want to see the content until the font has loaded (to avoid that font flicker)

– Alex
Jul 15 '14 at 10:53













The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

– rvighne
Jul 21 '14 at 0:05





The Web Fonts API is very useful when working with HTML5 Canvas. You can't use a font that hasn't finished loading before drawing text with it, and of course once the font is loaded it isn't automatically updated. Relatedly, the API is needed for tracking progress of loading assets, e.g. in a game.

– rvighne
Jul 21 '14 at 0:05




10




10





This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

– Gal
Apr 20 '15 at 4:38





This information should be on the Google Web Fonts page. It just presents the three options to you - and doesn't give any helpful hints as to which one to use and when.

– Gal
Apr 20 '15 at 4:38




2




2





Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

– James Cushing
Oct 20 '15 at 13:34







Google's own 'Getting Started' tutorial uses only the <link> method, so I guess that's the one they recommend in an unspoken fashion

– James Cushing
Oct 20 '15 at 13:34















-1














You can save some request time



...if you take some extra coding time.



It's really no big deal, just open Google's simplified one-line link:



   http://fonts.googleapis.com/css?family=Kameron:400,700


and see what it gives you:



/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 400;
src: local('Kameron'), url(https://fonts.gstatic.com/s/kameron/v8/vm82dR7vXErQxuzngLk6Lg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 700;
src: local('Kameron Bold'), local('Kameron-Bold'), url(https://fonts.gstatic.com/s/kameron/v8/vm8zdR7vXErQxuzniAIfO-rpfQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


Yes, that's only a couple of other requests. It's faster to start with these directly - even faster if you download the font files to your own server and add a localhost URL before the Google ones. I know I know, we like CDNs and paralell requests, they are meant to be faster - but just try and see for yourself.



Now for the original question: don't @import, don't <link>, just put this code right into your existing global CSS, it's the best for your server. It needs no plus request, it's not a separate move - only a very slight increase in the size of the file which will add practically nothing to a request's processing time. Will it be beautiful to look at? No... But your site will hopefully get a lot more requests than revisions :) So help the server, not yourself.



Overall, I think it's worth the extra mile.



The one-line version is not designed to be efficient but simple - for bloggers who want the easiest possible way. You know better.






share|improve this answer





















  • 3





    Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

    – Punit S
    Nov 29 '18 at 11:45











  • @PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

    – dkellner
    Nov 29 '18 at 16:18


















-1














You can save some request time



...if you take some extra coding time.



It's really no big deal, just open Google's simplified one-line link:



   http://fonts.googleapis.com/css?family=Kameron:400,700


and see what it gives you:



/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 400;
src: local('Kameron'), url(https://fonts.gstatic.com/s/kameron/v8/vm82dR7vXErQxuzngLk6Lg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 700;
src: local('Kameron Bold'), local('Kameron-Bold'), url(https://fonts.gstatic.com/s/kameron/v8/vm8zdR7vXErQxuzniAIfO-rpfQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


Yes, that's only a couple of other requests. It's faster to start with these directly - even faster if you download the font files to your own server and add a localhost URL before the Google ones. I know I know, we like CDNs and paralell requests, they are meant to be faster - but just try and see for yourself.



Now for the original question: don't @import, don't <link>, just put this code right into your existing global CSS, it's the best for your server. It needs no plus request, it's not a separate move - only a very slight increase in the size of the file which will add practically nothing to a request's processing time. Will it be beautiful to look at? No... But your site will hopefully get a lot more requests than revisions :) So help the server, not yourself.



Overall, I think it's worth the extra mile.



The one-line version is not designed to be efficient but simple - for bloggers who want the easiest possible way. You know better.






share|improve this answer





















  • 3





    Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

    – Punit S
    Nov 29 '18 at 11:45











  • @PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

    – dkellner
    Nov 29 '18 at 16:18
















-1












-1








-1







You can save some request time



...if you take some extra coding time.



It's really no big deal, just open Google's simplified one-line link:



   http://fonts.googleapis.com/css?family=Kameron:400,700


and see what it gives you:



/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 400;
src: local('Kameron'), url(https://fonts.gstatic.com/s/kameron/v8/vm82dR7vXErQxuzngLk6Lg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 700;
src: local('Kameron Bold'), local('Kameron-Bold'), url(https://fonts.gstatic.com/s/kameron/v8/vm8zdR7vXErQxuzniAIfO-rpfQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


Yes, that's only a couple of other requests. It's faster to start with these directly - even faster if you download the font files to your own server and add a localhost URL before the Google ones. I know I know, we like CDNs and paralell requests, they are meant to be faster - but just try and see for yourself.



Now for the original question: don't @import, don't <link>, just put this code right into your existing global CSS, it's the best for your server. It needs no plus request, it's not a separate move - only a very slight increase in the size of the file which will add practically nothing to a request's processing time. Will it be beautiful to look at? No... But your site will hopefully get a lot more requests than revisions :) So help the server, not yourself.



Overall, I think it's worth the extra mile.



The one-line version is not designed to be efficient but simple - for bloggers who want the easiest possible way. You know better.






share|improve this answer















You can save some request time



...if you take some extra coding time.



It's really no big deal, just open Google's simplified one-line link:



   http://fonts.googleapis.com/css?family=Kameron:400,700


and see what it gives you:



/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 400;
src: local('Kameron'), url(https://fonts.gstatic.com/s/kameron/v8/vm82dR7vXErQxuzngLk6Lg.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin */
@font-face {
font-family: 'Kameron';
font-style: normal;
font-weight: 700;
src: local('Kameron Bold'), local('Kameron-Bold'), url(https://fonts.gstatic.com/s/kameron/v8/vm8zdR7vXErQxuzniAIfO-rpfQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}


Yes, that's only a couple of other requests. It's faster to start with these directly - even faster if you download the font files to your own server and add a localhost URL before the Google ones. I know I know, we like CDNs and paralell requests, they are meant to be faster - but just try and see for yourself.



Now for the original question: don't @import, don't <link>, just put this code right into your existing global CSS, it's the best for your server. It needs no plus request, it's not a separate move - only a very slight increase in the size of the file which will add practically nothing to a request's processing time. Will it be beautiful to look at? No... But your site will hopefully get a lot more requests than revisions :) So help the server, not yourself.



Overall, I think it's worth the extra mile.



The one-line version is not designed to be efficient but simple - for bloggers who want the easiest possible way. You know better.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 11:36

























answered Nov 26 '18 at 11:31









dkellnerdkellner

2,64011620




2,64011620








  • 3





    Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

    – Punit S
    Nov 29 '18 at 11:45











  • @PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

    – dkellner
    Nov 29 '18 at 16:18
















  • 3





    Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

    – Punit S
    Nov 29 '18 at 11:45











  • @PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

    – dkellner
    Nov 29 '18 at 16:18










3




3





Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

– Punit S
Nov 29 '18 at 11:45





Copying the contents of css from fonts.googleapis.com/css is not recommended. The content of this file changes based on the requesting browser. The above file is for browsers that support woff2 format and will cause issues on browsers that do not support woff2 (IE, opera mini, UC browser, etc)

– Punit S
Nov 29 '18 at 11:45













@PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

– dkellner
Nov 29 '18 at 16:18







@PunitS: Good point; for exotic browsers, you may need WOFF1. (It makes no real sense to care about Opera Mini, it gives a very different look anyway; but UC and IE are valid reasons for a fallback.)

– dkellner
Nov 29 '18 at 16:18




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12316501%2fincluding-google-web-fonts-link-or-import%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Create new schema in PostgreSQL using DBeaver