Title: Preconnect
Last modified: December 27, 2018

---

# Preconnect

 *  Resolved Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/)
 * Hi,
 * I’ve added a preconnect for [https://fonts.googleapis.com](https://fonts.googleapis.com)
   but this appears in the source code below my fonts ([https://fonts.googleapis.com/css?family=&#8230](https://fonts.googleapis.com/css?family=&#8230);)
   which are right at the top of the page.
 * So i’m wondering if there’s any point in using preconnect for [https://fonts.googleapis.com](https://fonts.googleapis.com)?
 * Thanks

Viewing 15 replies - 1 through 15 (of 15 total)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11031048)
 * > So i’m wondering if there’s any point in using preconnect for [https://fonts.googleapis.com](https://fonts.googleapis.com)?
 * no, not really 🙂
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11031180)
 * That’s what I thought 🙂
 * Is there anyway to get the preconnect appearing before the fonts?
 * I have tried adding them manually into the header.php right before the <head>
   but AO seems to add the fonts before my preconnects no matter what i do.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11031686)
 * Even if it would appear before the fonts, it would not really matter; as I see
   it preconnect is only useful for requests that occur later (i.e. deferred requests/
   requests triggered by javascript/ requests from within CSS or -maybe- requests
   at the end of your HTML).
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11033947)
 * Would the use of preconnect differ from that of dns-prefetch?
 * I ask because according to this ([https://www.keycdn.com/blog/resource-hints](https://www.keycdn.com/blog/resource-hints))
   recommended uses of prefetch include google fonts (see section 2 – dns prefetching).
 * My understanding was that preconnect is basically a better version of prefetch
   which is why i was using it for the fonts.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11033978)
 * preconnect indeed > dns-prefetch, as preconnect not only does the dns-lookup,
   but also establishes the tcp/ip and HTTP connection.
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11034006)
 * My point was that in the previous comment you said it’s not useful for google
   fonts but keycdn says it is? Confused…
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11034011)
 * When in doubt; test 🙂
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11034022)
 * Perhaps you forgot my original message? 🙂
 * I am unable to insert the preconnect before the fonts in the page source, even
   if i try adding it manually as AO always inserts the fonts before the preconnect.
 * I’m assuming that for preconnect to actually be useful it must be inserted before
   the fonts which your original reply seemed to suggest was the case.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11034740)
 * right-o 🙂
 * so you could switch to [autoptimize beta (on github)](https://github.com/futtta/autoptimize/archive/beta.zip)
   which has a filter (`autoptimize_filter_extra_gfont_injectpoint`) that allows
   you to alter the injection-point (which is now `<link`)?
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035569)
 * Is that filter on this page as i couldn’t find it?
 * [https://github.com/futtta/autoptimize/](https://github.com/futtta/autoptimize/)
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035605)
 * it’s here; [https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeExtra.php#L261](https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeExtra.php#L261)
   🙂
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035632)
 *     ```
       $injectpoint = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' );
               $out         = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) );
               unset( $fonts_collection );
       ```
   
 * This code will cause google fonts to be inserted after <link rel=”preconnect”?
 * Do i just copy/paste the code, or do i need to modify the `'<link'` bit to `link
   rel="preconnect"`?
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035671)
 * no, that code will (by default) inject the optimized Google Font code before 
   the first `<link` tag but allows you to override that with a code snippet that
   hooks into that `autoptimize_filter_extra_gfont_injectpoint` filter 🙂
 * You can find more info on filters in WordPress here;
    * [https://www.wpbeginner.com/glossary/filter/](https://www.wpbeginner.com/glossary/filter/)*
   [https://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers](https://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers)*
   [https://developer.wordpress.org/reference/functions/add_filter/](https://developer.wordpress.org/reference/functions/add_filter/)
 * hope this clarifies 🙂
    frank
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035684)
 * thanks
 *  Thread Starter Anonymous User 14978628
 * (@anonymized-14978628)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035751)
 * I think when the new AO version is released you might want to make this easier
   for people.
 * As currently if i use the settings in AO to preload fonts and preconnect the 
   fonts, essentially the preconnect doesn’t have any effect as it occurs after 
   the preload.
 * Speaking of preload, are we any closer to seeing AO css/js assets being preloaded?

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Preconnect’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 15 replies
 * 2 participants
 * Last reply from: Anonymous User 14978628
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/preconnect/#post-11035751)
 * Status: resolved