Giter Site home page Giter Site logo

Comments (7)

danielroe avatar danielroe commented on July 24, 2024 1

@Irelynx I think your configuration was wrong. Here's a working example:

export default defineNuxtConfig({
  // the $production alias is not _within_ the nitro config
  $production: {
    nitro: {
      publicAssets: [
        {
          baseURL: '/fonts',
          // if you pass a relative path it is relative from the `~/server` directory
          dir: '../public/fonts',
          maxAge: 35,
        },
      ],
    },
  },
})

from nuxt.js.

stackblitz avatar stackblitz commented on July 24, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from nuxt.js.

danielroe avatar danielroe commented on July 24, 2024

When you are running nuxi preview you are not running a Nitro server so it is not able to set any headers. Instead you are previewing a static site (namely, a folder full of assets).

If you are generating a static site you will need to configure headers on your site differently, by configuring whatever is serving it.

from nuxt.js.

Irelynx avatar Irelynx commented on July 24, 2024

Hi and thanks for the reply.

I tried different approach and started Nuxt app using node .output/server/index.mjs - same result.
How then i should start application to make headers works in this case?


When i tried to hook every request/response (using defineNitroPlugin) i see only request related to pages, so technically you are correct, yes. But how static resources served then?

from nuxt.js.

Irelynx avatar Irelynx commented on July 24, 2024

I guess the only working way is using routeRules (doesn't work for nuxi preview, but works for node .output/server/index.mjs:

export default defineNuxtConfig({
  // ...
  routeRules: {
    '/fonts/**': {
      headers: {
        'cache-control': `public,immutable,max-age=${60 * 60 * 24 * 365},s-maxage=${60 * 60 * 24 * 365}`,
      },
    },
  },
  // ...
}

from nuxt.js.

Irelynx avatar Irelynx commented on July 24, 2024

@danielroe
Sorry for ping, but i guess this issue should be reopened.

from nuxt.js.

Irelynx avatar Irelynx commented on July 24, 2024

Oh..
Yeah, you are right, $production was inside of nitro, and when I moved it to comply with your example - cache-control header appeared!

Thanks again for your time!

from nuxt.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.