April 04, 2019 • ☕️ 2 min read
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"
Personal blog by Serge van den Oever - als je maar lol hebt...
LinkedIn: Serge van den Oever - articles on LinkedIn
Technology Consultant @ Macaw
Competence Team Lead Custom Application Development @ Macaw
2022 Technology Sitecore Most Valuable Professional
2021 Technology Sitecore Most Valuable Professional