2

Should I put .js in front of .css, or .css in front of .js files? Which is better? I'm working on a html5 project with jquery.

2

4 Answers 4

1

A general rule is to put stylesheets (.css) at the top and scripts (.js) at the bottom. But be careful, you might not be able to put all your scripts at the bottom.

Sign up to request clarification or add additional context in comments.

Comments

0

Try using http://headjs.com/ which will optimize loading of JS and CSS. http://requirejs.org/ is also a good framework for handling this.

Comments

0

I'd suggest you use the HTML5 Boilerplate which makes decisions like this for you based on best practices formulated by top front-end developers over the last 4 years. The code is really well commented and the documentation is excellent so you can easily learn more about the thinking which informed the various decisions, but if you just want to get on with building your page, safe in the knowledge that your foundation is sound, you can.

Comments

-1

There is no better way. As long as they are all in the header there is no difference in their order unless they depend on each other.

EDIT: The above is true in most simple cases.

Ideally, you should put all of your CSS styles in the HEAD element and all of your SCRIPT elements in the order of dependence at the end of the BODY element (directly before the ending </body>).

Different orders can make some difference in newer desktop browsers. In mobile browsers, speculative parsing is not available, so the browser waits for requests of scripts before any other loading is performed.

tl;dr - It doesn't really matter as the differences are trivial, especially if your frontend has heavy JavaScript dependence.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.