2
\$\begingroup\$

I am a new SO/SE user and I initially asked this question on SO, but i was 'sent' here -for some reason i don't clearly understand but anyway- so here I am..! I was actually curious about my require.js setup, cause it is the first time I 'm using it and having seen many different approaches/examples, I am not sure if what I 've done so far is correct. So, on my index I have on the "head"

<script data-main="js/app" src="js/vendor/require-2.2.0-min.js"></script>

and at the end of my 'body' I have the Google Analytics snippet. No other script is loaded directly from index.

On app.js that is inside my $projectroot/js folder I have:

requirejs.config({
   "baseUrl": "js/vendor",
   "paths": {
      "app": "..",
      "jquery" : ['//code.jquery.com/jquery-1.12.4.min','jquery-1.12.4.min'],
      "modernizr" : 'modernizr-2.8.3-respond-1.4.2.min',
      "bootstrap" : ['//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min','bootstrap.min'],
      "plugins": '../plugins'
    },
    "shim": {
       "bootstrap": ["jquery"],
       "plugins": ["bootstrap"]
    }
});

requirejs(["app/main"]);

Also, my main.js which is on the same folder with app.js contains:

define([
   "jquery",
   "modernizr",
   "bootstrap",
   "plugins"
], function($)
{
$(function()
{
console.log('required plugins loaded...');
});
});

Finally, my plugins.js (again, on the same folder with main.js and app.js) is NOT a library, but some custom js code that I need to be loaded last. Is this ok so far? Any drawbacks with this approach? Would it be ok to add the rest of my custom js code on a similar manner?

\$\endgroup\$
5
  • \$\begingroup\$ Welcome to Code Review, and thanks for mentioning your cross-post. This question would have been off-topic on Stack Overflow because there is no specific programming problem to be solved — you're just asking for an opinion on something that already works. \$\endgroup\$ Commented Jun 3, 2016 at 17:38
  • \$\begingroup\$ That said, there isn't much code here to review. You may or may not get an answer. \$\endgroup\$ Commented Jun 3, 2016 at 17:39
  • \$\begingroup\$ Thank you for making it clear for me. This is from a minimal example I made and I only posted the code that is relevant to my question.. \$\endgroup\$ Commented Jun 3, 2016 at 17:48
  • \$\begingroup\$ This being Code Review and not Stack Overflow, I encourage you to post more code — perhaps even all of it. \$\endgroup\$ Commented Jun 3, 2016 at 17:50
  • \$\begingroup\$ This would be like trying to teach an old dog new tricks, but I will keep your advice in mind..!! \$\endgroup\$ Commented Jun 3, 2016 at 17:58

0

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.