Keywords: GitHub | HTML file execution | raw.githack.com
Abstract: This article explores how to run HTML files directly on GitHub instead of just viewing their source code. By analyzing the limitations of GitHub's raw file service, it introduces the raw.githack.com tool, detailing its support for GitHub, Bitbucket, GitLab, and GitHub Gists. The conversion process from raw URLs to executable HTML links is explained, including different endpoints for development and production environments, with additional tools like GitHub HTML Preview as alternatives.
In software development, it is common to host HTML files on version control platforms like GitHub, such as for running JavaScript test suites. However, GitHub serves HTML files as plain text by default, with the MIME type set to text/plain, which prevents browsers from directly rendering and executing JavaScript code. Users typically need to download or clone repositories locally to run these files, adding complexity to development and testing workflows.
Limitations of GitHub's Raw File Service
GitHub provides raw file access via raw.githubusercontent.com, but this service is designed for file downloading rather than content execution. For example, an HTML file from the jQuery test suite (e.g., https://raw.githubusercontent.com/jquery/jquery/master/test/index.html) opens as plain text in a browser, rather than running the tests. This occurs because the server response header sets Content-Type to text/plain, not text/html. Technically, this mitigates security risks like cross-site scripting attacks but limits direct preview capabilities.
Solution Using raw.githack.com
raw.githack.com is a third-party service that addresses this issue by proxying GitHub's raw files and setting the correct MIME type, enabling HTML files to run directly in browsers. The tool supports multiple platforms, including GitHub, Bitbucket, GitLab, and GitHub Gists, offering both development and production environments.
GitHub URL Conversion Example
For GitHub, the raw URL format is https://raw.githubusercontent.com/[user]/[repository]/[branch]/[filename.ext]. Using raw.githack.com, this can be converted to:
- Development Environment (throttled):
https://raw.githack.com/[user]/[repository]/[branch]/[filename.ext] - Production Environment (CDN-based):
https://rawcdn.githack.com/[user]/[repository]/[branch]/[filename.ext]
For instance, the jQuery test file can be converted to https://raw.githack.com/jquery/jquery/master/test/index.html, allowing tests to run directly in the browser.
Support for Other Platforms
raw.githack.com also extends support to other version control systems:
- Bitbucket: Raw URLs like
https://bitbucket.org/[user]/[repository]/raw/[branch]/[filename.ext]can be converted tohttps://bb.githack.com/[user]/[repository]/raw/[branch]/[filename.ext](development) orhttps://bbcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext](production). - GitLab: Raw URLs like
https://gitlab.com/[user]/[repository]/raw/[branch]/[filename.ext]can be converted tohttps://gl.githack.com/[user]/[repository]/raw/[branch]/[filename.ext](development) orhttps://glcdn.githack.com/[user]/[repository]/raw/[branch]/[filename.ext](production). - GitHub Gists: Raw URLs like
https://gist.githubusercontent.com/[user]/[gist]/raw/[revision]/[filename.ext]can be converted tohttps://gist.githack.com/[user]/[gist]/raw/[revision]/[filename.ext](development) orhttps://gistcdn.githack.com/[user]/[gist]/raw/[revision]/[filename.ext](production).
Additional Tools
Beyond raw.githack.com, GitHub HTML Preview (http://htmlpreview.github.io/) offers similar functionality. Users can prepend http://htmlpreview.github.io/? to an HTML file URL for preview, e.g., http://htmlpreview.github.io/?https://github.com/twbs/bootstrap/blob/gh-pages/2.3.2/index.html. Note that this tool is an independent project, not an official GitHub service, and may have limited features.
Technical Implementation and Considerations
The core of raw.githack.com lies in modifying HTTP response headers, changing Content-Type from text/plain to text/html, and potentially adding other headers to support cross-origin requests. This allows browsers to correctly parse HTML and JavaScript, enabling dynamic content execution. However, users should be aware of potential security issues, such as ensuring hosted content is trustworthy to avoid malicious code execution. Additionally, raw.githack.com's development environment has traffic throttling, suitable for testing, while the production environment uses a CDN, ideal for public projects.
In summary, tools like raw.githack.com enable developers to run HTML files directly on GitHub conveniently, enhancing development and testing efficiency. This highlights how third-party services innovatively complement platform limitations in modern web development.