Thu Apr 04 2019 • ☕️ 2 min read • you like my writing? Buy me a coffee
Sometimes there is the need to fetch the raw contents of a file from a GitHub repository. I have this case for a Markdown documentation file that I want to show in a web page. The url of this document is
https://github.com/macaw-interactive/react-jss-typescript-starter/blob/develop/README.md. When you request this url you get the contents of the GitHub page. There is also a “raw” version of this page where you navigate to when you select the “Raw” tab on the page. This leads you to the url
When this raw document is requested from GitHub it returns the required content, but it has two drawbacks:
text/plain; charset=utf-8while it should be
Both issues are very annoying when you are developing, and the second issue can be blocking for your purpose.
In the past I used the services of
https://rawgit.com/ to overcome these issues, but they decided to stop their services as stated on their website: RawGit has reached the end of its useful life.
With the jsDeliver service the required url looks like
https://cdn.jsdelivr.net/gh/macaw-interactive/react-jss-typescript-starter@develop/README.md, and it provides the correct content type!
But… it is cached on the CDN. What if the contents has changed? jsDelivr to the rescue: change the
purge in the url and the next request you get a fresh copy. Easy way to automate that in your package.json scripts:
"purge:readme": "npx req https://purge.jsdelivr.net/gh/macaw-interactive/react-jss-typescript-starter@develop/README.md"
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. You are free to share and adapt this work for non-commercial purposes, provided you give appropriate credit, provide a link to the license, and indicate if changes were made. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/.