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

Add CDN asset hosting option #1954

Open
wants to merge 3 commits into
base: dev/31-taconite
Choose a base branch
from

Conversation

iturgeon
Copy link
Member

@iturgeon iturgeon commented Jan 25, 2022

Using a CDN for the compiled assets will free up the node server to focus on the tasks it's really needed for. Doing so will speed up the server, reduce server hosting costs, and speed up end user's load times.

Since this added env vars, I figured I'd add a list on configuration env vars to the readme.

Adds:

  • CDN_ASSET_HOST (optional)

To use a CDN, set CDN_ASSET_HOST=https://cdn.com
Then upload everything from packages/app/obojobo-express/server/public to the CDN after running yarn build for the exact version of the site you deploy.

To add further detail: yarn build uses webpack, and the assets are named with a name that includes a hash based on the content of the file. Webpack creates a manifest file that is used to look up this hash name - if obojobo is looking for 'fancy-file.js' the manifest is used to look up the built file's name fancy-file-<hash>.js. Because of this - the files on the CDN need to be updated when the js/css/images are updated because the updated build for obojobo will be looking for a new file by name.

This means the deploy process would need to include running yarn build then uploading the public folder to the CDN on every deploy of a new version of the application.

@iturgeon iturgeon force-pushed the issue/add-cdn-asset-hosting-option branch 2 times, most recently from c9608f3 to d18c254 Compare January 25, 2022 05:00
@iturgeon
Copy link
Member Author

UPDATE: The latest commit will allow module images to be loaded through a CDN as well.

This would require the CDN to be able to pass requests to /library/module-icon/* to obojobo server so the server can still build them, but the CDN can cache them

Supports setting an env var for CDN_ASSET_HOST.
Doing so will prepend the asset urls that are built
in asset_resolver with a cdn.

For this to work, you need to set CDN_ASSET_HOST=https://cdn.com
Then upload everything from packages/app/obojobo-express/server/public
to the cdn after running yarn build.
Now, setting CDN_ASSET_HOST will now prepend module image urls
to the configured CDN.  This required updates to some of the repository
changes to pass a server variable to the universal react pages so they
can render correctly on SSR and CSR environments.
@iturgeon iturgeon force-pushed the issue/add-cdn-asset-hosting-option branch from 8fdf35f to 0fefa40 Compare January 31, 2022 05:38
@FrenjaminBanklin FrenjaminBanklin changed the base branch from dev/27-pyrite to dev/28-jadeite February 8, 2022 18:36
@stale
Copy link

stale bot commented Aug 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep our backlog under control, but we thank you for your contributions.

@stale stale bot added the stale label Aug 13, 2022
@FrenjaminBanklin FrenjaminBanklin changed the base branch from dev/28-jadeite to dev/29-sodalite August 26, 2022 20:16
@RachelDau RachelDau self-requested a review May 10, 2023 13:27
@stale stale bot removed the stale label May 10, 2023
@RachelDau RachelDau changed the base branch from dev/29-sodalite to dev/31-taconite May 10, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant