When I use ngrok to load my Laravel app , it only displays basic html and no css

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Troubleshooting ngrok Issues with CSS and JS When Loading Laravel Apps Body: If you're developing a Laravel app locally and using tools like ngrok to share your website temporarily with your teammates, you might encounter issues with missing CSS and JavaScript. Here are some common solutions worth exploring that will help resolve these problems. 1. Use asset() in the right way: Often, developers use asset() to load local files from the public directory for development purposes. However, when shared through ngrok, it might not work correctly since the URL format changes. Instead of using asset("css/styles.css"), you can load assets directly by specifying their absolute path like this:
https://ngrok-host-name/public/css/styles.css
This will ensure the browser reads CSS files correctly. 2. Configure virtual hosts on your local machine: You can create virtual hosts for every project you're working on by using a hosts file (on Windows) or vhosts file (on Mac and Linux). In this setup, you will map a specific domain name to the local IP address of your development machine. This way, when you share the website address through ngrok, it should load properly with all assets. 3. Enable Cross-Origin Resource Sharing (CORS): Your Laravel app might use resources from external sources like Google Fonts or CDNs. If your groupmates don't have their own CORS settings configured for these services, you may experience issues loading your CSS and JS files. Consider disabling CORS check in your .env file by adding APP_DEBUG=true. But understand that this approach is not secure for production environments. 4. Use Laravel Mix: Laravel comes with a command-line tool called Laravel Mix to automate asset management. It bundles all of the resources and outputs them in a single file, making your app's URL more stable when you share it through ngrok. To initiate a new mix project, run npm install && npm run dev. Remember to reload the browser after each change, as Laravel Mix automatically updates the URL. 5. Use HTTP Headers: You can use HTTP Headers to specify which hosts are allowed to access your site and what resources they can load. This approach is more secure than changing CORS settings in the .env file. To set up the required headers, add this code at the top of your public/index.php file:
header('Access-Control-Allow-Origin: *'); // allows all origins to access your site
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS'); // specify the methods allowed for requesting resources
6. Use alternative tools for sharing locally hosted Laravel apps: If you're still struggling with ngrok, consider using services like LocalTunnel (https://www.localtunnel.io) or Ngrok GUI (https://github.com/ngrok-inc/ngrok-ui). These tools make sharing locally hosted web apps easier since they don't require configuring ngrok or modifying your app code. In conclusion, there are several ways to troubleshoot issues with CSS and JS when sharing Laravel apps through ngrok. From using the right asset() method to implementing more secure methods like HTTP headers, these solutions will help ensure that your teammates can access and edit the website from their homes efficiently. Remember to test each approach and choose the one that fits your project's requirements best.