Answers.Body: <p>You can tell Craft to generate new image transforms right when <a href="http://buildwithcraft.com/classreference/models/AssetFileModel#getUrl-detail" rel="nofollow">getUrl()</a> is called by setting the <a href="http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad" rel="nofollow">generateTransformsBeforePageLoad</a> config setting to <code>true</code>. Assuming you still want the default behavior on your main website, you can set the setting programatically from your endpoint config with <a href="http://buildwithcraft.com/classreference/services/ConfigService#set-detail" rel="nofollow">ConfigService::set()</a>:</p>
  
  <pre class="lang-php prettyprint-override"><code>'endpoint/path' =&gt; function() {
      craft()-&gt;config-&gt;set('generateTransformsBeforePageLoad', true);
  
      return [
          // ...
      ];
  },
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T21:43:20.633Z
Answers.Text: would this go in the `general.php` config?
Answers.UserDisplayName: seth
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T01:02:36.257Z
Answers.Text: @seth that code is for Craft 2 and would go in `config/elementapi.php`.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-07T21:39:40.017Z
Answers.LastActivityDate: 2015-09-08T12:16:22.607Z
Answers.LastEditDate: 2015-09-08T12:16:22.607Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm using the element API to get the url of an asset from angular with:</p>
  
  <pre><code>'image' =&gt; $entry-&gt;playerImage-&gt;first()-&gt;getUrl("square"), 
  </code></pre>
  
  <p>Problem is until i visit that image in the browser the url doesn't work, does someone know of a nice way of dealing with this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-28T14:43:40.613Z
Comments.Text: I'm actually not sure if this will work from the PHP side or not, so I'm adding it as a comment, but what happens if you set [generateTransformsBeforePageLoad](http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad) to `true`?
Comments.UserDisplayName: Brad Bell
Tags: <image-transforms><plugin-elementapi>
Title: Avoiding initial load for image transform
ThreadText: # Avoiding initial load for image transform
  
  (Asked by: username_0 on 2015-08-28)
  
  I'm using the element API to get the url of an asset from angular with:
  
  ```
  'image' => $entry->playerImage->first()->getUrl("square"), 
  
  ```
  
  Problem is until i visit that image in the browser the url doesn't work, does someone know of a nice way of dealing with this?
  
  **Tags:** image-transforms, plugin-elementapi
  
  > **Comments:**
  > **username_1**: I'm actually not sure if this will work from the PHP side or not, so I'm adding it as a comment, but what happens if you set [generateTransformsBeforePageLoad](http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad) to `true`?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-09-07. Score: 2
  
  You can tell Craft to generate new image transforms right when [getUrl()](http://buildwithcraft.com/classreference/models/AssetFileModel#getUrl-detail) is called by setting the [generateTransformsBeforePageLoad](http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad) config setting to `true`. Assuming you still want the default behavior on your main website, you can set the setting programatically from your endpoint config with [ConfigService::set()](http://buildwithcraft.com/classreference/services/ConfigService#set-detail):
  
  ```php
  'endpoint/path' => function() {
      craft()->config->set('generateTransformsBeforePageLoad', true);
  
      return [
          // ...
      ];
  },
  
  ```
  
  > **Comments:**
  > **username_3**: would this go in the `general.php` config?  
  > **username_2**: @username_3 that code is for Craft 2 and would go in `config/elementapi.php`.  
  
  ---
  
  