Question

Gin: Deeply Rooted Static Files Not Loading

I have a gin application in which not all the static files load. Deeply rooted static files do not load.

### **Static file path**

##    repository

        assets

           project_1

             css/style.css

             vendor/aos/bootstrap

Files in the **aos ** folder do not load, but files in the **css ** folder load. I have tried router.Static(“/asset”, “./repository/assets”) but it does not work.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
March 25, 2024

Hi there,

The issue you’re facing with Gin where some deeply nested static files are not loading while others are could be related to how the static file serving is set up. When you use router.Static("/asset", "./repository/assets"), it should theoretically serve all files under the ./repository/assets directory accessible via the /asset endpoint. However, there might be nuances affecting the accessibility of files in deeper nested directories.

You need to verify the URL you’re using to access the files. For instance, the file at assets/project_1/css/style.css should be accessed via http://yourserver/asset/project_1/css/style.css. Similarly, a file at assets/project_1/vendor/aos/bootstrap/file.css should be accessible at http://yourserver/asset/project_1/vendor/aos/bootstrap/file.css.

Also, check that the server has the necessary permissions to read the files in the aos and other nested directories.

If the above steps are correct, consider testing with a more explicit static file serving setup for the problematic directory to see if it resolves the issue:

router := gin.Default()

router.Static("/asset", "./repository/assets")
// Explicitly define the path for nested directories if needed
router.Static("/asset/project_1/vendor/aos", "./repository/assets/project_1/vendor/aos")

router.Run(":8080")

Along with the above add logging to your application to check whether the requests for the static files are hitting the server and how they’re being resolved. It might provide insights into why certain files aren’t being served.

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel