Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
James White
847 PointsHow do I load external css file instead of having them inline within the html file?
In this video, Chalkers creates a commonHeaders variable with Content-Type: text/html to be able to properly load the html files
However, if I decided to remove the CSS code and place it in a separate main.css and create a link inside the html file, it won't work, the page loads but without any styles.
How can this be solved?
var commonHeaders = {'Content-Type': 'text/html'};
function home(request, response) {
if(request.url === '/') {
response.writeHead(200, commonHeaders);
render.view('header', {}, response);
render.view('search', {}, response);
render.view('footer', {}, response);
response.end();
}
}
1 Answer
Ioannis Leontiadis
9,828 PointsHello James,
you should handle the request which is generated from your html file.
Make your server serve the CSS file at '/someName.css' as you did with the html file at '/' .