-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with ssr-caching #4
Comments
I didn't try it yet, but it should work like this with the caching example: const express = require('express')
const next = require('next')
const routes = require('./routes')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dir: '.', dev })
const handle = app.getRequestHandler()
const LRUCache = require('lru-cache')
const ssrCache = new LRUCache({
max: 100,
maxAge: 1000 * 60 * 60 // 1hour
})
app.prepare().then(() => {
express().use(renderAndCache).listen(3000)
})
function renderAndCache (req, res) {
if (ssrCache.has(req.url)) {
return res.send(ssrCache.get(req.url))
}
// Match route + parse params
const {route, params} = routes.match(req.url)
if (!route) return handle(req, res)
app.renderToHTML(req, res, route.page, params).then((html) => {
ssrCache.set(req.url, html)
res.send(html)
})
.catch((err) => {
app.renderError(err, req, res, route.page, params)
})
} |
Ah nice, will try 🙂 It might be helpful to document in README the |
I'll do that! Let me know if you encounter any issues. Closing this for now |
I tried in this branch: https://github.com/relatenow/relate/tree/ssr-caching But I get in the server:
And in the console: The |
I tried adding this before checking the cache: if (req.url === '/__webpack_hmr') {
return handle(req, res);
} But still get
|
I also think that somehow, the |
OK for some reason the console error doesn't appear any more (although I thought I had restarted the server to clear the cache). The next issue is that it doesn't match on all the prefetcher routes, although this is the most important load that the server will get (most of the time, the server will only need to render when the user visits the home page, then the rest of SSR will only be triggered by the SSR requests):
|
I asked about this issue in the original PR: vercel/next.js#497 (comment) |
And I replied to myself 😄
|
It doesn't since the catchall update from the last version, can you check? I just updated Also you can now use |
Seems to work 👍 (sedubois/relate@f8032ba#diff-bba6db1dd9623c6662b43cc660a5975cR20) |
Update dependency concurrently to v3.6.1
Next.js provides a great SSR caching example which makes use of Next.js'
renderToHTML
andrenderError
. Can next-routes somehow be used in conjunction with this or could this be implemented?https://github.com/zeit/next.js/tree/master/examples/ssr-caching
The text was updated successfully, but these errors were encountered: