Skip to content
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

Serve multiple routes from the same generated HTML #52

Open
dgp1130 opened this issue Oct 28, 2022 · 0 comments
Open

Serve multiple routes from the same generated HTML #52

dgp1130 opened this issue Oct 28, 2022 · 0 comments
Labels
feature New feature or request

Comments

@dgp1130
Copy link
Owner

dgp1130 commented Oct 28, 2022

Consider the use case of a product catalog. You likely want users to visit /product/1234.html to view the product. The only real way to accomplish this with rules_prerender today is to iterate over all product IDs and generate distinct pages:

export default function*(): Generator<PrerenderResource, void, void> {
  for (const productId of productIds) {
    yield PrerenderResource.of(`/product/${productId}.html`, renderProduct());
  }
}

This has two key problems:

  1. It requires build-time knowledge of all product IDs. This may not feasible or even useful if product specific data is loaded and rendered on the client.
  2. It duplicates most of the rendering work per-page unnecessarily. If all product pages are identical with only CSR differentiating them, then there's no value in duplicating the generated content.

It would be great to configure routes, so that the same product page could be served at multiple URLs. This is even more useful if SSR is implemented, since these pages could dynamically SSR different content based on the request URL, without duplicating the SSG content.

This feature fundamentally requires a server with knowledge of these routes and can't be a static HTTP file server. If we do implement SSG which requires a generated server anyways, then this becomes a very compelling feature. If we can define some syntax which indicates that /product/[^/]* should actually serve the SSG'd /product.html page, it would satisfy this use case. SSR/CSR could fill in any remaining content with knowledge of the request URL, while SSG doesn't need to know all the products or duplicate it's effort per-product.

@dgp1130 dgp1130 added the feature New feature or request label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant