-2

according to this:

https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-6-move-scripts-bottom-7200.html

but lets imagine an MVC system. You are inside the body, and try to use $(document).ready. It wont work since jQuery is not loaded. Then what?

EDIT: so

<body>
here I need jQuery. But it wont works since its not loaded. Then how to workaround this?
</body>
<script src='jquery>
John Smith
  • 6,129
  • 12
  • 68
  • 123
  • 1
    In the article it states "from the top to as low in the page as possible" which would seem that if you need jQuery sooner load it sooner. – nerdlyist Oct 29 '15 at 14:49
  • 2
    … then you haven't moved that script to the bottom. – Quentin Oct 29 '15 at 14:50
  • 1
    I think it starts off badly with "described how stylesheets near the bottom of the page". This isn't actually valid HTML, not back then anyway and `scoped` has little support even now. – Shikkediel Oct 29 '15 at 14:51

3 Answers3

2

You seem to be confusing physical position of the script statement with logical availability. Any scripting that executes after jQuery is loaded has jQuery available, regardless of whether it is loaded by a tag that appears physically higher in the page than the tag that loads jQuery.

chaos
  • 122,029
  • 33
  • 303
  • 309
1

It will parse the file, you can still use jQuery. If you have a custom script (if you're using a MVC framework you should) that requires jQuery make sure jQuery parses first.

Like so:

<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
Peter Girnus
  • 2,673
  • 1
  • 19
  • 24
0

MVC is not relevant. MVC is server side technology and jQuery is browser side technology. jQuery will run on a page generated by PHP, MVC, classic ASP or straight HTML text documents or anything else your browser can render.

This the OP's question is a duplicate of and is answered in: jQuery: Why use document.ready if external JS at bottom of page?

Community
  • 1
  • 1
Wolfie
  • 1,801
  • 1
  • 14
  • 16
  • 1
    MVC now includes client side frameworks such as AngularJS, Ember.js, JavaScriptMVC and Backbone. – Peter Girnus Oct 29 '15 at 15:03
  • almost good answer. But if I dont need .ready, I still need jQuery to attach events with – John Smith Oct 29 '15 at 15:09
  • Studio now comes with those things in templates, yes. However, those are not jQuery and that ($(document) is what the OP was asking about. And as I said, the OP's answer lies in the other SO post. – Wolfie Oct 29 '15 at 16:59