4 ms·
I must be missing something. What is the advantage of this approach versus hosting the index.html on a CDN as well?
by fzaninotto 5y ago
I must be missing something. What is the advantage of this approach versus hosting the index.html on a CDN as well?
- nileshtrivedi 5y agoThe first page gives users control on what code ends up being loaded with access to their data over API. First page coming from CDN, would not just be an issue for cross-origin resource sharing, also removes the ability to use SRI hash for subsequent JS. Also, the HTML page on CDN wouldn’t know what endpoint (domain, port) user has deployed their API on. One more thing for user to configure. Here, the HTML configures window.postgrest_url which the JS code can use.
- fzaninotto 5y agoIn the example, the SRI hash is not computed by the database, it probably comes from a build phase. This build phase can (or often does) generate the HTML at the same time it computes the JS file. As for configuration, I see it as a minor improvement over manually deploying one (or several) index.html with the API URL conf. The CORS issue is the bigget sbenefit I think, but easy to accomplish in a CDN with custom headers, or with a custom domain. So I think that it's smart, but it brings no benefit over existing approaches, and opens a whole new class of problem (like sizing your Postgrest instance for when the site is under attack, or visited by a bot).