The code: in the page or in a js file?

Hi again.

I have this piece of script:

$(document).ready(function(){
  $('.m_nav a').click(function(){
      $('.marken-box').animate({
          scrollTop: $( $.attr(this, 'href') ).offset().top
      }, 300);
      return false;
  });
});

And the question is very simple: in terms of performance, which would be the best solution? pasting it at the bottom of the page or creating a file and linking to it:?

<script src="js/the-script.js"></script>

This code is going to be used by many pages, but it is so light…

Have you tried creating pages doing it both ways? You could then see what you’re browsers’ dev tools are telling you about performance. My guess is that loading up the jQuery library would have more of an impact, but you may already have that cached.

separate file .js

And if you decide to change 300 to 280 you wouldn’t mind changing the many pages?
Then later when you want to change it to 310 ??

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.