Answers.Body: <p>You need to re-index your assets to show the correct URL after changes to your volume location when using imageOptimize. Just re-save the volume from within Craft CMS. Even if you have made amends to your volume config file you will need to re-save from within Craft CMS.</p>
  
  <p>To quote <a href="https://github.com/nystudio107/craft-imageoptimize/issues/78#issuecomment-385978902" rel="nofollow noreferrer">Andrew</a>, the plugin author...</p>
  
  <blockquote>
    <p>"So I want to say that this is normal (though maybe not desirable?)l.
    The URLs in the OptimizedImages fields get resolved at asset save
    time. So the full absolute URL to each image will resolve to whatever
    the alias is.</p>
    
    <p>Potentially this resolution could be postponed until runtime, but in
    the interim, if you re-index your assets on the environment."</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-12T15:41:16.193Z
Answers.LastActivityDate: 2018-12-12T15:41:16.193Z
Answers.UserDisplayName: Dan Lee
Body: <p>When I output my ImageOptimize field in the template, my images are not showing up. If you inspect the image url, it's missing a folder name I'm specifying as part of the url in my multi-environment setup and volume config.</p>
  
  <p>If I manually change the image url in the browser tools to include the missing folder, the image shows up. Other images are rendered fine when using the standard asset field code so I'm not sure what could be wrong.</p>
  
  <p><strong>Things to note:</strong></p>
  
  <ul>
  <li>I am using Andrew's <a href="https://github.com/nystudio107/craft3-multi-environment/blob/master/config/general.php#L42" rel="nofollow noreferrer">multi-environment setup</a>. </li>
  <li>I have two separate folders in my web root folder:
  
  <ul>
  <li>In the folder <code>assets/</code>, I'm serving my template assets like css, images, and fonts. </li>
  <li>In the folder <code>content/</code>, I'm serving the files uploaded to the volumes I have setup in Craft - images, logos, documents etc.</li>
  </ul></li>
  </ul>
  
  <p><a href="https://i.sstatic.net/fCZmd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fCZmd.png" alt="asset folder"></a></p>
  
  <p><strong>My environment variables:</strong></p>
  
  <pre><code>'BASE_URL' =&gt; $protocol . $httpHost . '/',
  
  'BASE_PATH' =&gt; realpath(dirname(__FILE__)) . '/web/content/',
  </code></pre>
  
  <p><strong>My aliases (set for all environments):</strong></p>
  
  <pre><code>'aliases' =&gt; [
      '@basePath' =&gt; getenv('CRAFTENV_BASE_PATH'),
      '@baseUrl' =&gt; getenv('CRAFTENV_BASE_URL'),
  ],
  </code></pre>
  
  <p><strong>My volume config:</strong></p>
  
  <pre><code>'*' =&gt; [
      'images' =&gt; [
          'path' =&gt; '@basePath/images',
          'url' =&gt; '@baseUrl/content/images',
      ],
  ],
  </code></pre>
  
  <p><strong>My ImageOptimize snippet:</strong> </p>
  
  <pre><code>&lt;img src="{{ optimizedImages.src() }}"
               srcset="{{ optimizedImages.srcset() }}"
               sizes="100vw" /&gt;
  </code></pre>
  
  <p><strong>The image path being used on the frontend (note the absence of the <code>content/</code> folder):</strong></p>
  
  <pre><code>&lt;img src="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg" srcset="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg 1920w"&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-12T15:25:44.130Z
Comments.Text: Have you tried resaving the asset volume when moved to a different environment?
Comments.UserDisplayName: andrew.welch
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-12T15:33:40.427Z
Comments.Text: The issue is discussed in more depth here: https://github.com/nystudio107/craft-imageoptimize/issues/78
Comments.UserDisplayName: andrew.welch
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-12T15:34:54.103Z
Comments.Text: I haven't moved to a different environment. But just resaved and it now works!
Comments.UserDisplayName: Dan Lee
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-12T15:37:52.040Z
Comments.Text: Oh nice, def add that as a solution Andrew!
Comments.UserDisplayName: Jalen Davenport
Tags: <assets><multi-environment><environmentvariables><plugin-imageoptimize>
Title: ImageOptimize not using image url specified in my multi-environment setup and my volume config
ThreadText: # ImageOptimize not using image url specified in my multi-environment setup and my volume config
  
  (Asked by: username_0 on 2018-12-12)
  
  When I output my ImageOptimize field in the template, my images are not showing up. If you inspect the image url, it's missing a folder name I'm specifying as part of the url in my multi-environment setup and volume config.
  
  If I manually change the image url in the browser tools to include the missing folder, the image shows up. Other images are rendered fine when using the standard asset field code so I'm not sure what could be wrong.
  
  **Things to note:**
  
  * I am using Andrew's [multi-environment setup](https://github.com/nystudio107/craft3-multi-environment/blob/master/config/general.php#L42).
  * I have two separate folders in my web root folder:
    + In the folder `assets/`, I'm serving my template assets like css, images, and fonts.
    + In the folder `content/`, I'm serving the files uploaded to the volumes I have setup in Craft - images, logos, documents etc.
  
  [![asset folder](https://i.sstatic.net/fCZmd.png)](https://i.sstatic.net/fCZmd.png)
  
  **My environment variables:**
  
  ```
  'BASE_URL' => $protocol . $httpHost . '/',
  
  'BASE_PATH' => realpath(dirname(__FILE__)) . '/web/content/',
  
  ```
  
  **My aliases (set for all environments):**
  
  ```
  'aliases' => [
      '@basePath' => getenv('CRAFTENV_BASE_PATH'),
      '@baseUrl' => getenv('CRAFTENV_BASE_URL'),
  ],
  
  ```
  
  **My volume config:**
  
  ```
  '*' => [
      'images' => [
          'path' => '@basePath/images',
          'url' => '@baseUrl/content/images',
      ],
  ],
  
  ```
  
  **My ImageOptimize snippet:**
  
  ```
  <img src="{{ optimizedImages.src() }}"
               srcset="{{ optimizedImages.srcset() }}"
               sizes="100vw" />
  
  ```
  
  **The image path being used on the frontend (note the absence of the `content/` folder):**
  
  ```
  <img src="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg" srcset="https://franklin.test/images/_1920x1080_crop_center-center_82_line/national-formulation-centre.jpg 1920w">
  
  ```
  
  **Tags:** assets, multi-environment, environmentvariables, plugin-imageoptimize
  
  > **Comments:**
  > **username_1**: Have you tried resaving the asset volume when moved to a different environment?  
  > **username_1**: The issue is discussed in more depth here: https://github.com/nystudio107/craft-imageoptimize/issues/78  
  > **username_0**: I haven't moved to a different environment. But just resaved and it now works!  
  > **username_2**: Oh nice, def add that as a solution Andrew!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-12-12. Score: 1 | Accepted answer
  
  You need to re-index your assets to show the correct URL after changes to your volume location when using imageOptimize. Just re-save the volume from within Craft CMS. Even if you have made amends to your volume config file you will need to re-save from within Craft CMS.
  
  To quote [Andrew](https://github.com/nystudio107/craft-imageoptimize/issues/78#issuecomment-385978902), the plugin author...
  
  > "So I want to say that this is normal (though maybe not desirable?)l.
  > The URLs in the OptimizedImages fields get resolved at asset save
  > time. So the full absolute URL to each image will resolve to whatever
  > the alias is.
  >
  > Potentially this resolution could be postponed until runtime, but in
  > the interim, if you re-index your assets on the environment."
  
  
  ---
  
  