-
Notifications
You must be signed in to change notification settings - Fork 30
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
Caching #36
Comments
I have abandoned server side rendering for my project for the time being (until someone else fixes it). In case you find yourself needing Server Side Rendering optimization features you can fork the repo and experiment on it. |
Hey @halt-hammerzeit, can you explain a bit more why you abandoned server side rendering? Was it for performance / caching reasons, complexity reasons, not needed by google anymore, etc? |
@vsaportas AFAIK google can parse javascript-rendered pages if the data is preloaded |
For me, SEO is the least of my concerns. SSR (and caching) are critical because I have a project with many large images above the fold. The standard method of linking to static assets causes the page to appear broken and jump all over the place as images are loaded in. Embedding 'above the fold' images as data URIs solves this, but causes a long delay of looking at nothing while the script loads. So I want to cache the rendered html, so that visitors can see content faster, and the moment they see it, it is already complete and doesn't jump all over the place while content loads in. For me, SSR is about the experience a user has while navigating to the site, and caching is about performance. SEO is a very distant concern. |
why aren't you setting height and width then
only small images are applicable to data uri to to max length constraint
Well, you could hook up somewhere in the web service wrapping the Then // Isomorphic rendering (Koa middleware)
web.use(async (ctx) =>
{
// Trims a question mark in the end (just in case)
const url = ctx.request.originalUrl.replace(/\?$/, '')
const total_timer = timer()
const cached = await cache.get(url)
if (cached)
{
ctx.body = cached.content
if (cached.status)
{
ctx.status = cached.status
}
}
// Not simply awaiting for the promise here to prevent Koa waiting for the render
const promise = render_page(settings,
{
application,
assets,
initialize,
localize: localize ? parameters => localize(parameters, get_preferred_locales(ctx)) : undefined,
render,
loading,
html,
authentication,
// The original HTTP request can be required
// for inspecting cookies in `preload` function
request: ctx.req,
// Cookies for authentication token retrieval
cookies: ctx.cookies
})
.then({ status, content, redirect, route, time })
{
if (redirect)
{
return ctx.redirect(redirect)
}
if (stats)
{
stats
({
url: ctx.path + (ctx.querystring ? `?${ctx.querystring}` : ''),
route,
time:
{
...time,
total: total_timer()
}
})
}
const result = { content, status }
cache.put(url, result)
return result
})
if (!cached)
{
const { content, status } = await promise
if (status)
{
ctx.status = status
}
ctx.body = content
}
}) |
I have an application where it makes sense to cache the entire rendered html, because there is no user authentication and data changes infrequently. I'd like to implement a simple caching strategy, where rendered output is saved to memcached/redis, and every request both serves any cached page, then renders and caches a new version for the next visitor.
Serving up a blank page is unacceptable for my application, and waiting 100ms+ for render-on-demand is similarly bad.
Is there a way you could expose hooks at both ends of the process? The pre-hook would need to be passed
res
andlocation
, and the post-hook would need to be passed thelocation
andhtmlstring
.Alternatively (or additionally), if you integrate something like Rapscallion, that would also solve my issues, and seems like a robust solution that would address all the concerns you raised in your caching write-up.
The text was updated successfully, but these errors were encountered: