Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static resources not loading on GitHub Pages

I have created a website and am trying to host it on git hub pages. My site is available at -

http://<username>.github.io/<project name>/ 

But the static files for my site are available at the following path -

http://<username>.github.io/css/site.css http://<username>.github.io/script/main.js 

The above path omits the <project name>

So whenever I hit the url my static files are not loaded.

Is there a way to make it work with the github url?

Note: When I use a custom domain everything works fine because the relative paths are fine in that case.

Temporary Solution I have created a User page instead of a Project page to overcome this issue.

like image 635
tusharmath Avatar asked Aug 02 '13 18:08

tusharmath


People also ask

Why my GitHub Pages is not working?

Solution: Verify the publishing source and published URL from your repository's settings tab. Double check that you are using the correct URL by visiting your repository's Settings, and scrolling down to the GitHub Pages section. You should see the URL where your site is published.

Is GitHub Pages static only?

GitHub Pages publishes any static files that you push to your repository. You can create your own static files or use a static site generator to build your site for you. You can also customize your own build process locally or on another server.

How long does it take for GitHub Pages to load?

Note: It can take up to 10 minutes for changes to your site to publish after you push the changes to GitHub. If you don't see your GitHub Pages site changes reflected in your browser after an hour, see "About Jekyll build errors for GitHub Pages sites."


2 Answers

The other option is to include the file .nojekyll in your top-level directory which tells github to just serve your pages with out trying to break them (this is useful if you are trying to post the oputput from sphinx which does not need any more parsing/munging/rewriting).

relevant link

like image 171
tacaswell Avatar answered Sep 20 '22 17:09

tacaswell


From the documentation to setup a custom domain:

Warning: Project pages subpaths like http://username.github.io/projectname will not be redirected to a project's custom domain.

This means that due to the relative paths you can either have the assets on your username.github.io/project-name or on your custom domain.

If you want them in the github one check what the documentation says about the baseurl configuration, it's at the bottom of the page, in the "Project Url Structure". It's simple you just need to add a

baseurl: /project-name 

row to your _config.yml and use the {{ baseurl }} tag in your permalinks, jekyll will do the substitutions. And to test it locally just run the server with this option

jekyll serve --baseurl '' 

Hope it helps :) Happy coding!

like image 24
mokagio Avatar answered Sep 17 '22 17:09

mokagio