Next.js Discord

Discord Forum

Statically build without any scripts?

Answered
DanTheMan827 posted this in #help-forum
Open in Discord
Avatar
I have a project that has no interactivity which I want to export as a static site, but the output still includes a bit of scripts for what I presume is react.

Is there a way to build without any of this and just give straight HTML and CSS?
Answered by joulev
Nextjs (or any react frameworks for that matter) is not suitable for zero-js webpages, period. You must use a different framework.
View full answer

11 Replies

Avatar
you can use static export to also get the HTML/CSS/JS assets for your application. You can read about it here:
https://nextjs.org/docs/app/building-your-application/deploying/static-exports#configuration
Avatar
they dont want "js" as its not interactive... and i dont think nextjs is the best fit for that anyway (like i use astro for this simpler side, but when client and server dynamicnes nextjs)
Avatar
I’m generating static files, but I want to generate them without any JS and just the static html and css
Avatar
ah mb
Avatar
Impossible.
Avatar
Not really an exact answer to my question, but I made a small script to remove scripts from an html file
const cheerio = require('cheerio');
const fs = require('fs');
const firstArg = process.argv.length > 1 ? process.argv[2] : null

if (firstArg && fs.existsSync(firstArg)) {
  const $ = cheerio.load(fs.readFileSync(firstArg));

  // Remove script tags
  $("script").remove();

  // Remove links as script
  $("link[as='script']").remove();

  // Write out the modified html
  fs.writeFileSync(firstArg, $.html())
}
If there was some way to mutate the html after being generated, it could be applied at that stage, but it's just a script to run post-build at this point.
Avatar
i mean i wonder if you could abuse webpack config
but i would say that you should reconsider using nextjs and instead use something simpler like astro if your not going to keep JS
(like you remove the cool prefetching and layouts not needing to rerender on client)
Avatar
Nextjs (or any react frameworks for that matter) is not suitable for zero-js webpages, period. You must use a different framework.
Answer