I’m trying to clean up my code so I’m putting all the stuff in my
<style></style>
In a CSS file. And I’m trying to do the same for my jQuery. So I created a Custom.js file. But do things like:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
Stay in html file or can I move them the Custom.js file? Also, I’m using a jQuery plugin called uscrollbar so I have this piece of code in my html file:
<script>
$(document).ready(function(e) {
$('#scroll_form').uscrollbar();
});
</script>
Can I also move that to Custom.js?
A much better question.
It’s best to keep links to external scripts in your HTML, it’s perfectly fine to have a few
<script>tags. Especially ones using a CDN!You can move your
document.ready()function to external JS, where all of your other JS is kept. But sometimes it’s easier to include small snippets like that directly in pages where it concerns only that page.When moving things to separate files, it’s important to include them in the right order.
Usually something like Modernizr at the top (
<head>), with jQuery near the bottom (just before</body>), followed by your plugins, followed by your custom scripts.