-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Ability to deploy non-html files to separate domain #2335
Comments
Wouldn't using |
It isn't flexible enough really. Imagine you had the following pages...
It puts all assets with a path as If you then use pathPrefix... that is also given to react router for prod build, so it would look like this...
Meaning the URLs we really wanted won't work, as the html renders, then react-router kicks in and says it doesn't know the URL it's on, and goes to 404. |
Throwing my hat into the ring, I have this need as well. Totally understand the argument that with a static site generator everything should be hosted on the CDN, but sometimes that's not practical. Would be great to have a configuration to load JS components and such from a different host. |
@KyleAMathews if you can advise on the API you think can work for it, I'd be happy to contribute this feature. This is a dealbreaker for our project as well. |
@wzrdzl could you write in detail what you need for your project? |
I need to be able to serve the In our SPA we simply use webpack's: publicPath: `//akamaized.net/w/${version}/resources/`, so we need something similar for the static website |
@wzrdzl Gatsby is using webpack as well so a Gatsby plugin could probably make the same tweaks to our webpack setup that you're doing for your SPA? |
@KyleAMathews This is also a sticking point for my use-case as well, need pretty much what @wzrdzl describes. HTML in: Should come from my server via: All assets (js, images etc) should come from (probably) something like: |
@Rob3rtH Gatsby is designed so you can put all files on the CDN. Perhaps give that a go? |
This would help us as well, though in our case it could be a separate domain or a path. Our path structure currently looks like this: Our blog is translated into 6 languages. When generating pages in Gatsby, we simply generate paths like Thus, we can't use the simple the rule we had so far (i.e. redirect everything that starts with Michał Piechowiak suggested using Our current idea (not yet tested) is to build our app 6 times, once for each language, and set An option to serve all non-html files from a different domain or a specific path, would be much simpler solution for us. Especially, that after we finish working on our blog, we want to create 2 other multi-language Gatsby apps and we'll have the same issue then. |
@KyleAMathews I'm investigating some issues we have with internal React errors showing up after every deployment and I'm trying to come up with possible scenarios when stuff can break ;) Here are 2 that can happen if someone deploys Gatsby app to a domain not backed up by CDN:
Using CDN would solve these problems, because it would still keep old files in its cache. However, just like the author of this issue, we host many apps at the same domain and Gatsby is just one of them, so I don't think we can easily make it, so that only Gatsby app uses our CDN. I'm not an ops person, so there might be other and better ways to solve these issues without changing Gatsby code, but allowing to specify a domain (and preferably a path as well) for non-html files would be pretty useful. |
On the first bullet point — you're always going to run into trouble when serving from two out-of-sync servers. You should build somewhere else and then copy the files onto the web server(s). This way you could also keep old files pretty easily. On the second bullet — I think there's an issue about Gatsby catching js load errors that'd handle this sort of thing. Ideally though you keep files from older builds around so old versions still work. |
Probably #7808 could be used to solve this issue as well. |
We're looking at adoption of Gatsby at PayPal and have the requirement that we need to load gatsby from our app servers, but would like to load static assets from a CDN. We currently manage this with our webpack apps by setting the |
@xjamundx could you give a concrete example of what you're trying to do? How I'm interpreting this (and correct me if I'm wrong) is something like the following:
Does that about line up with what you're looking for here? Note: we don't currently support this, but just want to make sure we're on the same page before we discuss further! |
@DSchau Yeah that could work 👍 (Our current system wouldn't have the full path until AFTER My current thought was to modify the servers that will be serving the gatsby-generated HTML and injecting |
@DSchau This proposal may cover it? #7808 (comment) |
Wouldn’t it require 2 different options? One would be dataPrefixPath that would cause the build process to physically put files into specified path (e.g. /blog-assets would output non-html files to ./public/blog-assets), the other would be e.g. dataDomainPrefix, that would just add prefix to generated paths (e.g. https://cdn.mydomain.com). |
I'm also wondering how to do this. I want to use Gatsby for an existing site that has a bunch of endpoints with server-side logic. So, I can't load the entire site from the CDN, but want to use a CDN for all the static files. |
Also would benefit my use case. I'm forced to serve our site internally at the moment and getting marked down for not using a CDN so would rather just host the index page internally and all the static assets via a CDN |
@Daniel15 @trickydisco78 I'm working on this now. We want to do this in a clean way that doesn't introduce subtle edge cases and can be tapped into cleanly via plugin authors with an exposed API (e.g. You can follow along on this branch for now, and I'll hope to get something up and ready as soon as possible. |
I really need this feature to integrate Gatsby to my existing web application.
So when building, i need to have ability to:
Basically, this feature will separate building non-html assets and html assets into its own folder. |
An application I'm working on requires this functionality, too. #10933 looks very promising, but (based on its description) likely won't be ready until after my initial rollout. In the meantime, I'm thinking I'll use sed to manipulate the asset paths after the production build and before the site has been deployed. Has anyone else come up with a similar solution? Were there any surprising edge cases you ran into? |
@ethagnawl you could probably use cheerio and the The basic idea is you'd query for links, scripts, and any other external links, and prefix them with your asset prefix. We can't highly encourage this technique, but in theory that should kinda work. I think there will be lots of edge cases. Anywhere we add a URL dynamically (e.g. with JS) will probably fail this check. Things like images (using gatsby-image), preloaded content, etc. will fail with this technique. |
@DSchau I looked into using |
thanks for making an effort to support this, it is super relevant for a project I'm working on. |
Don't forget about the |
We are also stuck at this issue. This should be solved. It is quite common for an API server to send initial HTML file and rest of the js/css loads from other CDN server. Please let us know the workaround till the issue get solved. |
@nsisodiya Perhaps you should try using @DSchau's proposed solution and, if you find anything unexpected, provide constructive feedback? (I used it on a simple project recently and it worked very nicely.) |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Exactly what I'm looking for. |
Hey @nyedidikeke, this is currently being worked on here: #12128. It's not complete yet, but there's instructions here if you'd like to test it out: #12128 (comment) |
This is great news! Thanks for your efforts on this feature, @DSchau! |
Published and available in [email protected]. Specifically, the following packages have been augmented with assetPrefix functionality.
Soon enough, the documentation will be available at /docs/asset-prefix/ (waiting for the build to complete), but you can get a sneak peek here |
is there any way to filter what assets will be referenced in this way, for me this only make sense for serving images, that need transformations, and having them done in each build in a CI server is nuts. |
Doing some search, there was an initial issue which was closed by the OP: #1369.
However, the work I'm presently doing means the gatsby page will sit behind a company wide domain with the assets ideally sitting behind our static domain. Think...
mywebiste.com/gatsby-page
should reference the non-html files that sit atmystaticcontent.com
. (so something likemystaticcontent.com/gatsby-page/js-file.js
).I understand that from your point of view it should all just sit in 1 domain, but we have a very large website with a lot of applications and routing being fronted by a load balancer.
At present, it isn't feasible as well because the URL we want to use for the present page we have build is a top level URL, such as
mywebsite.com/gatsby-page
, but we can't really serve the assets from the top level domain as well.We did look at the gatsby documentation which has path prefix (so not allowing us to put it in a different domain altogether, but at least trialing putting the assets somewhere else), which puts the whole project under a certain path, but this also does it for react router. We added two rules into our load balancer, one for the URL we want the HTML page to resolve to, and another for the path prefix resolving to the public folder. But when viewing the page in the browser, react-router kicks in and doesn't understand the URL and send you off to the 404 page defined with gatsby.
We also looked into using modifyWebpackConfig and setting the public path just for webpack, but this doesn't seem to be picked up as part of
headComponents
in the html.jsx file (as it is still setting the link refs to/some-js-file.js
.The text was updated successfully, but these errors were encountered: