Giter Site home page Giter Site logo

Comments (13)

Atinux avatar Atinux commented on April 29, 2024 4

@voidale it's planned to be added before the 1.0

from nuxt.js.

Atinux avatar Atinux commented on April 29, 2024 3

What do you think of an build.cdn option?

publicPath should not be changed to another directory (because of how Nuxt.js static middleware works), but having a cdn option makes it clear it has to be an URL.

Example of nuxt.config.js:

module.exports = {
  build: {
    cdn: 'https://example.cnd.com/nuxt/'
  }
}

I will also make the generation of the JS files to have a chunkName (nuxt.bundle.986293.js) so on the CDN, there won't be any cache problems.

from nuxt.js.

dohomi avatar dohomi commented on April 29, 2024 1

Just as a reference, I think serverless had a quite nice approach to move all files from specific folder to a S3 bucket:
https://github.com/serverless/examples/tree/master/aws-node-single-page-app-via-cloudfront
They used the aws-cli internally and synced the folder to the destination bucket. I think it would be great to pick up this idea, because for leverage browser caching and setting expired headers it would be neat to store JS, CSS and images outside of the webserver location.

You guys doing a great job, haven't used it much yet but looking forward to use it in an upcoming project.

from nuxt.js.

Atinux avatar Atinux commented on April 29, 2024

Hi! I'm happy that your team like nuxt.js :)

To be sure, all files in your static folder will be on the CDN, but not the generated JS and CSS files from Nuxt.js right?

from nuxt.js.

jiangfengming avatar jiangfengming commented on April 29, 2024

No, I mean the files generated by Nuxt.js (webpack behind the scene), that is, the .nuxt/dist folder. Just as the output.publicPath config examples does. (https://webpack.js.org/configuration/output/#output-publicpath)

Maybe I will remove server-bundle.js before putting the files on to CDN, as it doesn't need on client side.

from nuxt.js.

jiangfengming avatar jiangfengming commented on April 29, 2024

I think CDN and static middleware are mutually exclusive. If you set publicPath a value begin with /http(s):/, then static middleware shouldn't on. Otherwise, middleware should serves files under that path, hard coded a /_nuxt/ path in URL is not so good. so I think we can reuse publicPath and determine by Regex, whether assets are hosted by self or on CDN.

from nuxt.js.

Atinux avatar Atinux commented on April 29, 2024

I added /_nuxt/ to avoid conflicts between the static folder and the generated files of Nuxt.js.

I might be able to add build.publicPath but if it's not an url, it can create problems with nuxt generate for static web apps generation.

from nuxt.js.

markudevelop avatar markudevelop commented on April 29, 2024

@Atinux
Your proposed addition of CDN url is perfect with chunkName (nuxt.bundle.986293.js) and it's how should work been using this approach with Meteor it works great.

Could this be added? I'm currently editing it manually to the CDN

As for @fenivana for public assets that are located in /static/ you can manually or create a helper function to generate a full CDN url so instead of:

<img src="/logo.png" />

<img src="https://example.cloudfront.net/logo.png" />

from nuxt.js.

cj avatar cj commented on April 29, 2024

@Atinux I noticed you're setting nuxtStatic to false automatically https://github.com/nuxt/nuxt.js/blob/0.9.10/lib/build.js#L88-L91. I think this should be a manual thing otherwise service like cloudfront won't work. Cloudfront works by grabbing the files from the main url if they aren't cached yet. I.e. if you have https://mysite.cloudfront.net/static/favicon.ico and Cloudfront doesn't have that file, it will grab it from https://mysite.com/static/favicon.ico. So in that case nuxtStatic will still need to be true.

from nuxt.js.

titanew avatar titanew commented on April 29, 2024

@Atinux If I also support http and https, I would begin with '//xxx.xxx.com' instead 'http://xxx.xxx.com' or 'https://xxx.xxx.com'.

from nuxt.js.

Atinux avatar Atinux commented on April 29, 2024

I updated the code to take care of it as well @rubyless

from nuxt.js.

Atinux avatar Atinux commented on April 29, 2024

The 0.10 release it out ✋

It took a while but it's now fully working!

from nuxt.js.

lock avatar lock commented on April 29, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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.