<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>

CC BY-SA 4.0
2018-11-08T21:43:20.633Z
would this go in the `general.php` config?
seth
CC BY-SA 4.0
2018-11-09T01:02:36.257Z
@seth that code is for Craft 2 and would go in `config/elementapi.php`.
Brandon Kelly
CC BY-SA 3.0
2015-09-07T21:39:40.017Z
2015-09-08T12:16:22.607Z
2015-09-08T12:16:22.607Z
Brandon Kelly
<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>

CC BY-SA 3.0
2015-08-28T14:43:40.613Z
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`?
Brad Bell
<image-transforms><plugin-elementapi>
Avoiding initial load for image transform
# 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() is called by setting the 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():
'endpoint/path' => function() {
    craft()->config->set('generateTransformsBeforePageLoad', true);

    return [
        // ...
    ];
},

> **Comments:**
> **username_3**: would this go in the `general.php` config?  
> **username_2**: @seth that code is for Craft 2 and would go in `config/elementapi.php`.  

---

