Next.js: Asset download during nextjs export

Created on 18 Jan 2020  路  8Comments  路  Source: vercel/next.js

Feature request

A related conversation to this feature happened here https://github.com/zeit/next.js/issues/9524#issuecomment-574568879

if i use a headless CMS (even wordpress or graphcms or whatever), the asset url is used in the static html.

There are two preferences here - that asset links be used as such.
But more likely - download the asset, build the html (link to it locally) and then layer a CDN in front. This is the far more acceptable practice.

This also ties in very well with using deployment systems like Netlify - which have a far, far more suitable globally available infrastructure than something like DatoCMS or Graphcms. So if im using Netlify as deployment, i would want everything to be served from Netlify domain and let it work its magic.

We understand that this increases build times. This is ok for our usecase where we use a CMS just for the sake of usability, but deployment has to follow guidelines of compliance (geographic restriction of assets, etc) so we would like the entire build to be inside the export folder. This would mean that CMS that have CDN in front of it (e.g. datocms and www.datocms-assets.com which is Imgix) may not be ideal.

There are tons of similar requests.

https://spectrum.chat/next-js/general/how-would-you-handle-importing-remote-images-on-nextjs-static-export~30b2ba84-bc27-4da7-9ec8-21e4d5d287a3

on gatsby side as well - gatsbyjs/gatsby#14076

https://spectrum.chat/gatsby-js/general/adding-remote-images-during-node-creation~e704e6fb-24b2-46c6-b1fc-93189d2e28a4

https://github.com/njosefbeck/gatsby-source-stripe/#downloading-files

Most helpful comment

I think it should also avoid duplicate downloads and allow post processing of whatever was downloaded afterwards.
So you mark something as an asset in getStaticProps and then in another magic export you do something with it. (Resize, compress etc)

All 8 comments

This is covered by #9524

@Timer sorry for the late response. but this is NOT covered by #9524 . In fact, i was told there to open a new issue since this will not be considered for inclusion under SSG improvements.

Is it possible to do this using any kind of custom code, etc ? this is the only thing blocking us from moving entirely to Nextjs from Gatsby.

@Timer I think @sandys is right here, I'm not seeing anything in that RFC which would solve this issue? Please correct me if I'm wrong, since I'd like to make use of this feature too since I switched to almost 100% SSG pages with the canary builds.

hi guys,
now that nextjs 9.3 is released with next-gen SSG support ( https://nextjs.org/blog/next-9-3#next-gen-static-site-generation-ssg-support ), im wondering if there is any way to achieve what was mentioned in this bug ?

@timer - any chance you can take a look at this and comment ? if there's a way to do this using the existing Nextjs framework, that would be awesome as well.

Any news on this? Ideally this should just store images fetched during getStaticProps on .next/static/images like the rest of the images of the website. The fetching will only happen on build time (getStaticProps), so this shouldn't be a problem technically.

I think it should also avoid duplicate downloads and allow post processing of whatever was downloaded afterwards.
So you mark something as an asset in getStaticProps and then in another magic export you do something with it. (Resize, compress etc)

Any news on this?

Was this page helpful?
0 / 5 - 0 ratings