Support Forums

CACHED and CDNs = next.js?

hello, so im stuck with this code —

const express = require(‘express’)
const serveStatic = require(‘serve-static’)

const app = express()

app.use(serveStatic(‘dist’, {
setHeaders(res, path) {
const isRevved = /[a-f0-9]{7,}/.exec(path)
? max-age=31536000,immutable
: max-age=0,s-maxage=31536000 )

const port = process.env.PORT || 3000
app.listen(port, () => console.log(Listening on port ${port}))

this is the website ----- https://loving-morse-5ebf27.netlify.app/

which its on the website, on the server.js file, i tried different approches but it doesnt seems to work, can you help me get this work?, and also can you recommend a plugin from netlify plugins to help me out resolve this issue, although if you can help me to get this out vanilla style, would be great

but now i ve made some research, and so i think this code was used using next.js, npm installs and all of that, so my question is, in order to get a good performance of a static website i need to to deploy it using next.js or react?

well, anyway, so i found some tutorials on next.js, if you know some good tutorials for my case, please letme know

and one last question, you know wordpress has plugins for ecommerce, would next.js have or has plugins for ecommerce?

thanks help!

Hi @lenguaestudiocreativ

Welcome to the Netlify community.

Your code which is in a file called server.js on your site is not client-side code, it is server-side code which is why you see ReferenceError: require is not defined. You do not need this to make your site run.


You do not require this code on your website when hosted with Netlify, and as per this Support Guide you cannot actually run it.

Netlify uses the Jamstack. You can use many tools including Next.js, React, Vue and NuxtJS and others to make your static site. You could also choose to do hand-craft HTML, CSS, and JS files and deploy them to Netlify.

Not necessarily. Any standards-based site that followed best-practices, regardless of how it is build should perform well.

Have a look at Netlify Explorers for some basics on getting started with Next.js and NuxtJS.

There is information on the Next.js site regarding commerce. I haven’t used this so cannot offer a comparison to WordPress commerce plugins like WooCommerce. If you want a simple way to get started with selling on Netlify have a look at this blog post Learn How to Accept Money on Jamstack Sites in 38 Minutes.

hi coelmay, so yeah,
“Not necessarily. Any standards-based site that followed best-practices, regardless of how it is build should perform well.”
i was thinking the same, and so how could i make it perform better?..im searching for a code to set up max age and the 200 status to cache in and all, but i cant find it anywhere, i still want to do this custom website right and then move on to next.js or jamstack, its jamstack another framework like next.js or gatsby? (…to later compare the performance of the custom to the framework)
i also know about service worker but that doesnt help the SEO…
well anyway hope you can help me

Instead of worrying about performance, I think you might wish to address the current errors presented by your site

Have a look at this recent thread on caching assets which links to the following support guide and related blog post on caching with Netlify. If you still want to cache after reading them you would need something like the example in the docs.

In short, no. This question is best answered by referring to the Jamstack link in my previous post.

You might wish to read [Support Guide] Understanding & unregistering service workers regarding this.

hello coelmay dude, thanks for the info and support, so i found this article Custom headers | Netlify Docs
now the thing is that i want to do this in a custom website without frameworks, so i guess i just need a code to use on the .js file, and since i havent found one on the web im wondering if such thing exist at all, can you help me out? i really dont know what to do…

I am really not sure what you are asking.

The method you use to build a site has nothing to do with custom headers on Netlify.

right this custom headers are for frameworks or something like that, its very simple what im asking, i just need a code to use on the .js file for caching and all of that, to get my files a 200 status and not a 304, and im not sure if such thing exist at all, so i guess im not clear on that part, anyways, if you can get me one would be awesome!

I do not understand what you are trying to do.

Also, @lenguaestudiocreativ, kindly do not open multiple topics about the same thing. I’ve replied to your other topic here: