Skip to content

fix(ipx): pass maxAge to ipx options - #706

Merged
pi0 merged 1 commit into
nuxt:mainfrom
yjl9903:main
Jan 27, 2023
Merged

fix(ipx): pass maxAge to ipx options#706
pi0 merged 1 commit into
nuxt:mainfrom
yjl9903:main

Conversation

@yjl9903

@yjl9903 yjl9903 commented Jan 10, 2023

Copy link
Copy Markdown
Contributor

fix #704

Pass ipx maxAge option from nuxt.config.ts.

// nuxt.config.ts

export default defineNuxtConfig({
  // ...
  image: {
    ipx: {
      maxAge: 2592000,
    },
  },
  // ...
})

@netlify

netlify Bot commented Jan 10, 2023

Copy link
Copy Markdown

👷 Deploy request for nuxt-image-v1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 2ed4def

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 changed the title fix: pass ipx maxAge option from options fix(ipx): pass maxAge to provider Jan 23, 2023
@pi0 pi0 changed the title fix(ipx): pass maxAge to provider fix(ipx): pass maxAge to ipx options Jan 23, 2023
@pi0
pi0 merged commit 5a49fab into nuxt:main Jan 27, 2023
procrates pushed a commit to procrates/nuxt-image that referenced this pull request Feb 21, 2023
@guillaumeprevost

Copy link
Copy Markdown

This doesn't seem to be working (I'm using v0.7.1 with Nuxt2), even after setting the following config,

  image: {
    ipx: {
      maxAge: 8380800, // 97d
    },
    ...
 }

The max-age of cache for all IPX images remained 300 seconds.

I found a workaround After looking into the code of IPX library : I configured its max-age header by setting the environment variable IPX_MAX_AGE so that the lib itself would read the env variable and set it

But that is only a workaround that bypasses entirely the configuration that should be achievable through nuxt-image.

@yjl9903

yjl9903 commented Mar 6, 2023

Copy link
Copy Markdown
Contributor Author

This doesn't seem to be working (I'm using v0.7.1 with Nuxt2), even after setting the following config,

  image: {
    ipx: {
      maxAge: 8380800, // 97d
    },
    ...
 }

The max-age of cache for all IPX images remained 300 seconds.

I found a workaround After looking into the code of IPX library : I configured its max-age header by setting the environment variable IPX_MAX_AGE so that the lib itself would read the env variable and set it

But that is only a workaround that bypasses entirely the configuration that should be achievable through nuxt-image.

This PR fix this bug in the main branch for nuxt3, not for nuxt2.

Related code in v0 branch for nuxt2 still has this issue. Maybe you can open another PR to fix it for nuxt2.

image/src/ipx.ts

Lines 11 to 16 in 075d1c3

const ipxOptions: ImageProviders['ipx'] = {
dir: resolve(nuxt.options.rootDir, moduleOptions.dir),
domains: moduleOptions.domains,
sharp: moduleOptions.sharp,
alias: moduleOptions.alias
}

@pi0 pi0 mentioned this pull request Mar 31, 2023
@SteveChurch

Copy link
Copy Markdown

This seems to work fine for me when running locally dev but when publishing to DigitalOcean in production it defaults to 300 for all ipx files.

Example:
https://dislist.gg/_ipx/f_webp/images/blog/single/dislist-blog-post1.png

 image: {
    ipx: {
      maxAge: 8380800,
    }
  },
  nitro: {
    publicAssets: [
        {
          baseUrl: "images",
          dir: "public/images",
          maxAge: 60 * 60 * 24 * 365,
        },
    ],
    routeRules: {
      "/img/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/images/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/_nuxt/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/_ipx/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
    }

@yjl9903

yjl9903 commented May 24, 2023

Copy link
Copy Markdown
Contributor Author

This seems to work fine for me when running locally dev but when publishing to DigitalOcean in production it defaults to 300 for all ipx files.

Example: https://dislist.gg/_ipx/f_webp/images/blog/single/dislist-blog-post1.png

 image: {
    ipx: {
      maxAge: 8380800,
    }
  },
  nitro: {
    publicAssets: [
        {
          baseUrl: "images",
          dir: "public/images",
          maxAge: 60 * 60 * 24 * 365,
        },
    ],
    routeRules: {
      "/img/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/images/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/_nuxt/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
      "/_ipx/**": { headers: { 'cache-control': `public,max-age=31536000,s-maxage=31536000` } },
    }

@SteveChurch Maybe you can open a new issue to track this bug and provide some reproduction. I think it works on my prod env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change IPX Cache-Control max-age

5 participants