image icon indicating copy to clipboard operation
image copied to clipboard

IPX max-age configuration doesn't apply

Open yuzu-qroulland opened this issue 2 years ago • 15 comments

Hello,

I'm unable to increase the cache max-age of my images.

With the help of #704 , I've tried to define it via the image config with that code but it's not working.

image: {
    ipx: {
      maxAge: 60 * 60 * 24,
    },
  },
Capture d’écran 2023-09-18 à 09 39 45

I'm using nuxt:3.7.3 and @nuxtjs/image:1.0.0-rc.2

yuzu-qroulland avatar Sep 18 '23 07:09 yuzu-qroulland

Interested on this too. Not sure if the reproduction helps. It's always giving me a max-age of "31536000", no matter the maxAge value passed in config.

https://stackblitz.com/edit/github-ac11u5?file=app.vue

urbgimtam avatar Sep 19 '23 01:09 urbgimtam

Same..

Pierre-Saigot avatar Sep 22 '23 12:09 Pierre-Saigot

Same

krthr avatar Sep 25 '23 11:09 krthr

Hi everyone,

I'm coming back to you because I've found a solution in the meantime. 🥳

With the following statement the maxAge is well taken into account:

image: {
    ipx: {
        options: {
            maxAge: 31536000,
        },
    },
}

Just need to set the maxAge into an options object. 🧐

However, I don't know whether this is the expected behavior and therefore the documentation is out of date, or whether it's a design error. 👀

yuzu-qroulland avatar Sep 29 '23 16:09 yuzu-qroulland

@yuzu-qroulland yep, that works! thanks 👍

manchenkoff avatar Oct 01 '23 12:10 manchenkoff

Any update? @yuzu-qroulland

Nothing worked for me

rahulkumarsingh73690 avatar Nov 16 '23 13:11 rahulkumarsingh73690

just fyi, since I upgraded to Nuxt 3.8 it works even with default config like

image: {
    quality: 80,
    format: ['avif'],
    ipx: {
        maxAge: 60 * 60 * 24 * 365,
    },
},

manchenkoff avatar Nov 16 '23 14:11 manchenkoff

Thanks @manchenkoff for sharing.

My app is hosted in Digitalocean app platform and this is not working for me

image

Nuxt - 3.8 Nuxt/image - 1.0.0

rahulkumarsingh73690 avatar Nov 16 '23 15:11 rahulkumarsingh73690

Now the options key seems to have been removed from IPXRuntimeConfig and it doesn't work at all for me 😕 Nuxt - 3.8.2 Nuxt/Image - 1.0.0

cernymatej avatar Nov 25 '23 21:11 cernymatej

For me it is working with the following config:

image: {
        ipx: {
            maxAge: 60 * 60 * 24 * 365,
        },
    },
- Operating System: Darwin
- Node Version:     v18.19.0
- Nuxt Version:     3.9.0
- CLI Version:      3.10.0
- Nitro Version:    2.8.1
- Package Manager:  [email protected]
- Nuxt Image:       @nuxt/[email protected]

raphaelbernhart avatar Jan 02 '24 12:01 raphaelbernhart

I am currently facing a similar issue, but it seems to be limited to external domains.

Image from external domain image

Images from public dir image image

dependecies

{
  "devDependencies": {
    "@nuxt/devtools": "latest",
    "@nuxt/image": "^1.3.0",
    "@nuxtjs/fontaine": "^0.4.1",
    "@nuxtjs/google-fonts": "^3.0.2",
    "@nuxtjs/i18n": "^8.0.0",
    "@nuxtjs/tailwindcss": "^6.10.0",
    "@tailwindcss/forms": "^0.5.7",
    "@vueuse/core": "^10.7.0",
    "@vueuse/nuxt": "^10.7.0",
    "nuxt": "^3.9.3",
    "nuxt-icon": "^0.6.8",
    "nuxt-svgo": "^4.0.0",
    "vue": "^3.4.15",
    "vue-router": "^4.2.5"
  },
  "dependencies": {
    "@pinia/nuxt": "^0.5.1",
    "@splidejs/vue-splide": "^0.6.12",
    "photoswipe": "^5.4.3",
    "pinia": "^2.1.7",
    "qs": "^6.11.2",
    "vue-multiselect": "^3.0.0-beta.3"
  }
}

nuxt.config.ts

export default defineNuxtConfig({
  image: {
    provider: "ipx",
    ipx: {
      maxAge: 60 * 60 * 24 * 365,
    },
    domains: ["cms.kuvqfitjqf.cfolks.pl"],
    presets: {
      default: {
        modifiers: {
          quality: 90,
          format: "webp",
        },
      },
    },
  },
})

I am aware that this functionality was functional in the past. An illustrative example can be found at the following link: https://stackblitz.com/edit/github-ac11u5?file=app.vue. image

@pi0 Could you help me solve the problem?

gnidustotalus avatar Jan 24 '24 21:01 gnidustotalus

I am currently facing a similar issue, but it seems to be limited to external domains.

Image from external domain image

Images from public dir image image

dependecies

{
  "devDependencies": {
    "@nuxt/devtools": "latest",
    "@nuxt/image": "^1.3.0",
    "@nuxtjs/fontaine": "^0.4.1",
    "@nuxtjs/google-fonts": "^3.0.2",
    "@nuxtjs/i18n": "^8.0.0",
    "@nuxtjs/tailwindcss": "^6.10.0",
    "@tailwindcss/forms": "^0.5.7",
    "@vueuse/core": "^10.7.0",
    "@vueuse/nuxt": "^10.7.0",
    "nuxt": "^3.9.3",
    "nuxt-icon": "^0.6.8",
    "nuxt-svgo": "^4.0.0",
    "vue": "^3.4.15",
    "vue-router": "^4.2.5"
  },
  "dependencies": {
    "@pinia/nuxt": "^0.5.1",
    "@splidejs/vue-splide": "^0.6.12",
    "photoswipe": "^5.4.3",
    "pinia": "^2.1.7",
    "qs": "^6.11.2",
    "vue-multiselect": "^3.0.0-beta.3"
  }
}

nuxt.config.ts

export default defineNuxtConfig({
  image: {
    provider: "ipx",
    ipx: {
      maxAge: 60 * 60 * 24 * 365,
    },
    domains: ["cms.kuvqfitjqf.cfolks.pl"],
    presets: {
      default: {
        modifiers: {
          quality: 90,
          format: "webp",
        },
      },
    },
  },
})

I am aware that this functionality was functional in the past. An illustrative example can be found at the following link: https://stackblitz.com/edit/github-ac11u5?file=app.vue. image

@pi0 Could you help me solve the problem?

I have same problem, setting max age for ipx dont work with external domain. Only work with public folder path

Setting in nuxt config

image: {
    domains: ['api.kytosai.com'],
    provider: 'ipx',
    ipx: {
      maxAge: 60 * 60 * 24 * 7, // 7 days
    },
  },

External domain:

image

Public folder path

image

kytosai avatar May 25 '24 20:05 kytosai

I am currently facing a similar issue, but it seems to be limited to external domains.

Image from external domain image

Hello,

I'm facing the exact same issue than @gnidustotalus and @kytosai here, not able to set Cache-Control header for external domains.

Is there any news on a fix or at least a workaround? It's quite annoying to not be able to proxy cache images generated by IPX...

Thanks!

aetievant avatar Aug 13 '24 14:08 aetievant

I actually found a workaround which consist to deal with nuxt.config.js configuration and nitro route rules:

export default defineNuxtConfig({
  // [...]
  nitro: {
    routeRules: {
      "/_ipx/**": { headers: { 'cache-control': `public,max-age=691200,s-maxage=691200` } },
    }
  },
  // [...]
})

Not optimal but currently I will live with this, until there is a real fix to solve that issue.

Hope it helps!

aetievant avatar Aug 13 '24 14:08 aetievant