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

Feature: Automatic Static Optimisation #107

Closed
danielcondemarin opened this issue Jul 18, 2019 · 3 comments
Closed

Feature: Automatic Static Optimisation #107

danielcondemarin opened this issue Jul 18, 2019 · 3 comments
Labels
enhancement New feature or request nextjs 9.0

Comments

@danielcondemarin
Copy link
Contributor

Motivation

Nextjs 9 introduced Automatic Static Optimisation as per this RFC.

What does this mean for this serverless plugin?

This should reduce the number of Lambda functions provisioned by the plugin. Next 9 prerenders static pages as HTML files, which means this plugin could simply upload these to S3 and route the page requests via API Gateway or CloudFront.

Proposal

Given the following app:

pages/
├── stars.js
└── about.js
function Stars({ stars }) {
  return <main>Stars: {stars}</main>;
}

Stars.getInitialProps = async ({ req }) => {
  const res = await fetch("https://api.github.com/repos/zeit/next.js");
  const json = await res.json();
  return { stars: json.stargazers_count };
};

export default Stars;
function About() {
  return <main>Simple static about page. No server side stuff happening</main>;
}

export default About;

The above app produces the following built pages:

.next/serverless/pages/stars.js
.next/serverless/pages/about.html

The plugin will upload about.html to the assets bucket.
Requests to /about will be routed to S3 the same way assets are currently served by the plugin.

Requests to /stars would work as per current behaviour.

@romainquellec
Copy link

This PR is awesome as a lot of project has static/marketing pages.

@RichiCoder1
Copy link

For the implementation, would this be be filtering out .html from getNextPagesFromBuildDir and then adding another accumulator to addCustomStackResources that scans the pages dir and generates api-gw-proxy for all the .html pages it finds? Would risk hittin the resource limit, but I think that's a risk already.

@danielcondemarin
Copy link
Contributor Author

For next 9 support use the newly released component 🙏 https://github.com/danielcondemarin/serverless-next.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nextjs 9.0
Projects
None yet
Development

No branches or pull requests

3 participants