vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
12.98k stars 2.09k forks source link

serve static with CDN #736

Open lookis opened 2 years ago

lookis commented 2 years ago

Is your feature request related to a problem? Please describe.

It's a feature request for better performance

Describe the solution you'd like

I would like to serve the static assets with CDN domains, maybe add some settings like cdnURL ?

Describe alternatives you've considered

No response

Additional context

No response

Validations

kiaking commented 2 years ago

Hi! Thanks for the feedback. But I'm not sure what you're looking for here 👀 Assets you mean you would like to do ![](https://cdn.com/filename.jpg)...? In that case I think you alredy can? Can you elaborate a bit more?

lookis commented 2 years ago

@kiaking thanks for your reply, as you can see, vitepress generate dist folder with assets (js/css) in it, and the html refer these js/css with relative path:

Screen Shot 2022-06-13 at 22 21 06

and I want to serve these static file with cdn server like these:

    <link rel="stylesheet" href="http://some.cdn.server/docs/assets/style.e172b030.css">
    <link rel="modulepreload" href="http://some.cdn.server/docs/assets/app.2986626d.js">
    <link rel="modulepreload" href="http://some.cdn.server/docs/assets/guide_api.md.48406c4b.lean.js">

if i change base config to the cdn link prefix, all links to html will be the cdn address too, which is not I want.

So, i think we can add cdn prefix for generated assets to speed up file loading

kiaking commented 2 years ago

Ah OK. So basically you want everything but html files to served from different domain. It might be easy to do this for imported assets like images but might be more complicated on generated js files since we need to modify manifest json as well...?

How do you deploy the site? Do you push assets folder to CDN provider after the build? Or is your hosting service take care these things?

lookis commented 2 years ago

Yes, you got it.

In my case, my cdn provider will pull the resource from origin server if assets missing, So, I don't need to push these files as long as the file with hash in it's name.

kiaking commented 2 years ago

Gotcha. Thanks for the info!

I think this is not that easy issue to solve, but if anyone wants to tackle it. PR welcome 👍