-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Support static site rendering #70
Comments
Hi @dlindenkreuz what do you mean with |
@impronunciable I assume @dlindenkreuz means rendering an application written with Next to static HTML that could be served up without a backend. |
Static site rendering would allow to save the output of all pages once and host it in S3 or any other static hosts without the need of running a server/node.js see: https://www.staticgen.com/ Would definitely be a huge plus to have. |
Exactly @ejulen @sebastianmacias: a statically rendered website would eliminate the need for a Node server. This is certainly only possible in some scenarios e.g. without dynamic routes or user input processing but would allow things like Github Pages hosting. |
For dynamic routes, it's possible if you name the paths like |
@jiyinyiyong Can you elaborate on that? I checked your examples and don't understand the relation to this issue in particular. |
@dlindenkreuz I was trying to explain that dynamic router will still work when the app is built into static files. For example in this demo: http://vue-pages-workflow.mvc-works.org/ There is also an There are also more demos, well, I didn't try And it's true not all routes can work perfectly, for example |
I'd also like this. The problem with conventional static sites is that the Cheers, On Wed, 26 Oct 2016, 04:15 Sebastian Macias, notifications@github.com
|
@jiyinyiyong Ah, thanks for the explanation! Indeed, the page tree would need to be fixed and determinable at the time of compilation. Handling suffixes like Figuring out that tree should probably happen automatically in regards to the Next.js "spirit" of dropping components in @lpil You might want to check out Gatsby.js until this is available in Next.js 😉 |
Hi guys, I wonder how this feature will affect the usage of Doesn't it give us to opportunity of prefetching data on the server side? (like async-props and redux-connect) |
@altayaydemir Yes, but the thing is that some projects do not need or can not have a dynamic backend (like GitHub Pages). In these cases, a bunch of static HTML files and directories are created at compile time. Prefetching data e.g. from JSON files can still happen at compile time but won't happen again when opening a page, because the page is then just a standalone HTML file. After you compile once, no Node.js server is involved anymore. |
This would definitely be a huge plus for me. I started to migrate a static website to Next just to notice it's "build" command didn't really built an static structure :( |
@dlindenkreuz ok, I get it. I thought I've missed something about the getInitialProps part. I've made a similar config to one of my active projects (with webpack / react-router code splitting) and I totally agree with you about this. |
This would definitely be a huge plus for me. I wanted to use Next.js for a couple specific projects but front-end code must be statically hosted and then using GraphQL and API's with a back-end for anything that must be needed. Static Hosting can still use JS so Webpack, Babel, React, Router, Redux, etc. are all still on the table but it has to be purely "front-end" with anything back-end done as a request (or as we will be doing in our app an Apollo/GraphQL subscribe for live-data to a separate back-end). Next.js seemed unable to do this so we went with create-react-app and built things the harder way... would like to know if this is an idea liked by the core team and will happen. Note: since I do a lot of static sites just some solid advice.. anyone considering GitHub Pages should really look at Netlify.com instead as they do not limit plugins, do continuous deployment to a GitHub repo (push triggers deploy), allows you to state your build command, env vars, outpur dir, etc. as well as give custom domain and SSL in the free tier. (They also have free Pro tier for open-source projects). |
Just noticed the "Feature Request: build mode which outputs all html files #162" and I would suggest that this can be done more in a SPA (Single Page App), PWA (Progressive Web App) using Service Workers, offline support, etc. if it is enabled to do "front-end only" builds... no need for "static html only files" unless that was also wanted. I think SPA/PWA/SW with router and "front-end only" is easier and not a big change from a standard Next.js just takes detaching the back-end and making it something "plug and playable" by services like Scaphold.io and others that can give you a back-end as a service with database and auth api's. (my 2 cents) |
Isn't that "just" a matter of recusive wget ? |
As an alternative, I tried to get the static content using I use Does anyone of you know the reason of this? Could it be a conflict with the Here the commands that I use with
|
I'm definitely +1 to this feature, but in gathering my thoughts on this topic, I've come to some conclusions that I think are worth pointing out: All the static hosting services mentioned have a server in the backend that is doing more than just serving static files – they provide a routing layer, handle caching, etc. The problem next.js will run into trying to support this is the dynamic nature of So what we really want is either next.js to work on more platforms (Github Pages, Netlify, Surge, S3 + Cloudfront) or for these platforms to become more capable like Heroku, Dokku, Now, EC2. If we focus on making next.js work on more platforms, I don't think a truly dynamic |
For static pages we'll also have to switch to hash history instead of html5 browser history (so url's use |
I may be wrong but if you use client side routing, what's the point of having next.is ? |
Why would you need URL rewriting? |
React Router and other implementations would be fine as client side only.
…On Sun, Dec 4, 2016, 10:34 Christian Schlensker ***@***.***> wrote:
@jonaswindey <https://github.com/jonaswindey>
For static pages we'll also have to switch to hash history instead of
html5 browser history (so url's use #/path instead of /path since I think
most static hosting don't support url rewritings.
Why would you need URL rewriting?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#70 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAQ9ljmLrlSgAQpyPc8HHM8C-OhbGZukks5rEjTjgaJpZM4KgfZ0>
.
|
There's definitely a use case for both, but what's missing right now from next.js is generating HTML pages that only require the JS that they need (code-split across pages). A SPA with client-side routing is quite a bit simpler and could probably be done without next.js |
Give a try to |
@jferrettiboke I don't think so. Where did you read about an export feature? |
@jferrettiboke I think you misunderstood Guillermo Rauch. Pretty sure he was saying he wanted static site generation, too, and gave an example of what that command could look like. |
Thanks @ejulen. I think you are right. I had a misunderstood. Sorry for the inconvenience. |
@rauchg any comment about your "export" idea? |
Basically |
So we won't be able to handle dynamic routes? For example let's say I want dynamic pages to list pages with a given content (eg: I have a collection of blog posts and want to have pages for each tags - /tag/{a tag}), there won't be a way to support that? |
Could this somehow support the |
For now here is what I do to allow people to generate whatever routes they want:
<Route component={ AppContainer }>
<Route path="showcase" component={ Showcase } />
<Route path="showcase/tag/:showcaseTag" component={ Showcase } />
<Route path="*" component={ DocsPageContainer } />
</Route>
This thing will not work (or with a lots of limitation) for me at some point since react-router v4 API is totally different and people can defined recursive urls by creating small piece of urls in any components. That's a good idea but it's just not really compatible with my approach (or I will need to tell people that there are many limitation like "hey you can use react-router v4 but not really as you need to explicitly pass a bundle of routes and nested routes will be ignored"). From my knowledge of next, there is no router (fs is the router) and the only way to have dynamic urls is using the programmatic API.
For now I cannot think of another way: since there is no router with routes defined, we cannot really guess what value to map. Another thing to think about is "redirection". It will be nice to be able to define urls to generate redirect code like jekyll-redirect does (tldr: you just output a meta refresh tag with the new url - it's not very clean but works and is considered as 301 by google (I asked on a google forum, I get an answer for a google engineer that said "lots of people still use that so we have to") |
@MoOx it's still possible that for the purpose of |
That would be awesome and will offer full control to developers :) |
Yep last night I had a dream about this feature and I think it will be
great :)
– @rauchg <https://twitter.com/rauchg>
…On Fri, Dec 9, 2016 at 7:39 AM, Maxime Thirouin ***@***.***> wrote:
That would be awesome and will offer full control to developers :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#70 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAy8W2ZT5pbeK5aXHYCjAwiA7cQboDTks5rGXYrgaJpZM4KgfZ0>
.
|
Dreams are the best POC :D
|
I think at some point, programmatic API and "no routes" will never be enough if you want to support stuff like pagination. |
@MoOx yep i've kept thinking about this, and for exporting statically, a route map option (via JSON for example) will be pretty interesting. |
FWIW, i've done this successfully on the last project i worked on: "routes": {
"/": "/landing",
"/signup": "/signup",
"/signup/*": "/signup",
"/login": "/login",
"/me/edit/password": "/me-edit-pass",
"/me/edit/bio": "/me-edit-bio",
"/article/manual": "/article-manual",
"/article/manual/*": "/article-manual",
"/article/auto": "/article-auto",
"/about": "/about",
"/404": "/404",
"/access-restricted": "/access-restricted",
"/privacy": "/privacy",
"/tos": "/tos",
"/imprint": "/imprint",
"/:author": "/profile",
"/:author/:article": "/profile"
} Allowing static pages with dynamic routing. This was in the package.json, but since there's a next.config.js, it could go in there. |
Very cool! |
@matthewmueller can you please provide more information on routing map? Thanks. |
Building on @jferrettiboke's #!/bin/bash -e
ADDR=${ADDR:-'http://localhost:3000'}
DEST=${DEST:-'dist'}
PAGES_DIR=${PAGES_DIR:-'pages'}
echo "starting server..."
next build
next start 2>&1 > /dev/null &
echo "downloading static assets..."
wget --html-extension \
--recursive \
--convert-links \
--page-requisites \
--no-parent \
--directory-prefix "$DEST" \
--no-host-directories \
--restrict-file-names=unix \
--quiet \
--retry-connrefused \
--waitretry 2 \
--tries 5 \
-i <(find "$PAGES_DIR" -type f | \
sed "s:^$PAGES_DIR\(.*\)\.js\$:\1:g" | \
sed 's:/index$:/:g' | \
sed "s,\(.*\),$ADDR\1,g")
echo "closing server..."
pkill -INT -g $$ node
wait
echo "done" |
Pretty impressive! Hopefully |
We'll move the discussion from here to #604 |
That's not quite right. There's no server-side router. Caching is prepared at build time then the site is literally served over CDN. What "etc."?
What we want want is to build react apps with client-side (JS) routing to work as static sites. I think you're confused by the word "static"--which is not uncommon. Static sites can do a lot of dynamic things thanks to client-side JS scripts and third-party APIs. . But the "server" only does the same thing every time: it runs a build process once per atomic build. Nothing more. "Netlify is a build tool with CDN hosting--having that become like Heroku is not what we what. That would miss the whole point of static sites. |
@Maxhodges take a look at https://www.netlify.com/docs/redirects/. At some layer in their stack there is dynamic server-side routing. The difference is that either we are managing that infrastructure or they are. Of course I'd love next.js to be managed by them. In other news, if anyone would find this useful, I created a standalone module for doing what I described here: #70 (comment) https://github.com/matthewmueller/next-route Right now this is for the server, but I'm hopeful that once next has static builds, this will be the format of the routing. |
Redirects aren't really what I'd consider application routing. Redirects transform the URL before the router creates a router state out of it. we are going with gatsbyjs |
Looking at the overall project structure, this seems like a rather easy step on your roadmap. Maybe someone from the team can provide a good starting point for contributors?
The text was updated successfully, but these errors were encountered: