Answers.Body: <p>Do you mean lazy load or <a href="https://craftcms.com/docs/3.x/dev/eager-loading-elements.html" rel="nofollow noreferrer">eager load?</a></p>
  <p>Usually you lazy load images via JS to speed up site loading but not I'm not sure doing it to one image across multiple pages is all that beneficial?</p>
  <p>After the initial load, the browser should cache that image and &quot;reuse&quot; it. However, querying the global set certainly has a cost on the database.</p>
  <p>As far as eager loading, not sure it'll make a huge difference here and it looks like you're not outputting any transforms but you might consider using, say, <a href="https://craftcms.com/docs/3.x/dev/tags.html#cache" rel="nofollow noreferrer"><code>{% cache globally %}</code></a> tag on your header. That'll save you some db queries that can have an affect on performance.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-03T20:48:52.120Z
Answers.Text: Good catch! I meant eager-loading, to reduce the number of db queries. I'm not trying to solve a specific performance issue, just to improve my Craft knowledge. As for the cache, it's indeed a good solution but we're already using it.
Answers.UserDisplayName: nstCactus
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-03T16:24:31.240Z
Answers.LastActivityDate: 2020-09-03T16:33:11.553Z
Answers.LastEditDate: 2020-09-03T16:33:11.553Z
Answers.UserDisplayName: RitterKnight
Answers.Body: <p>I know you can use this method to eager load fields on injected <code>entry</code>/<code>category</code> variables, so I'm assuming it would work for global sets as well:</p>
  <pre><code>{% do craft.app.elements.eagerLoadElements(
      className(header),
      [header],
      ['globalSetsHeaderLogo']
  ) %}
  
  {{ header.globalSetsHeaderLogo[0].logo.getImg() }}
  </code></pre>
  <p>You can find out more about this method for eager loading in <a href="https://nystudio107.com/blog/speed-up-your-craft-cms-templates-with-eager-loading#what-about-auto-injected-entrys" rel="noreferrer">this blog post</a> by Andrew Welch.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-04T04:11:54.850Z
Answers.LastActivityDate: 2020-09-04T04:11:54.850Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I use a <code>header</code> global set to store various thing about my site header, including the company's logo.</p>
  <p>I use it in my template like this:</p>
  <pre><code>{{ header.globalSetsHeaderLogo.one()logo.getImg() }}
  </code></pre>
  <p>Any idea on how I could eager-load this?</p>
  
Tags: <globals><eager-loading>
Title: Is there a way to eager-load fields in a global set?
ThreadText: # Is there a way to eager-load fields in a global set?
  
  (Asked by: username_0 on 2020-09-03)
  
  I use a `header` global set to store various thing about my site header, including the company's logo.
  
  I use it in my template like this:
  
  ```
  {{ header.globalSetsHeaderLogo.one()logo.getImg() }}
  
  ```
  
  Any idea on how I could eager-load this?
  
  **Tags:** globals, eager-loading
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-09-04. Score: 5 | Accepted answer
  
  I know you can use this method to eager load fields on injected `entry`/`category` variables, so I'm assuming it would work for global sets as well:
  
  ```
  {% do craft.app.elements.eagerLoadElements(
      className(header),
      [header],
      ['globalSetsHeaderLogo']
  ) %}
  
  {{ header.globalSetsHeaderLogo[0].logo.getImg() }}
  
  ```
  
  You can find out more about this method for eager loading in [this blog post](https://nystudio107.com/blog/speed-up-your-craft-cms-templates-with-eager-loading#what-about-auto-injected-entrys) by Andrew Welch.
  
  
  ---
  
  ### Answer by username_1 on 2020-09-03. Score: 2
  
  Do you mean lazy load or [eager load?](https://craftcms.com/docs/3.x/dev/eager-loading-elements.html)
  
  Usually you lazy load images via JS to speed up site loading but not I'm not sure doing it to one image across multiple pages is all that beneficial?
  
  After the initial load, the browser should cache that image and "reuse" it. However, querying the global set certainly has a cost on the database.
  
  As far as eager loading, not sure it'll make a huge difference here and it looks like you're not outputting any transforms but you might consider using, say, [`{% cache globally %}`](https://craftcms.com/docs/3.x/dev/tags.html#cache) tag on your header. That'll save you some db queries that can have an affect on performance.
  
  > **Comments:**
  > **username_0**: Good catch! I meant eager-loading, to reduce the number of db queries. I'm not trying to solve a specific performance issue, just to improve my Craft knowledge. As for the cache, it's indeed a good solution but we're already using it.  
  
  ---
  
  