2

Prepros has useful feature:

//@prepros-prepend filename.js

which includes js file at the beginning of current one, but I need to include files inside jquery document.ready statement, which would look like so:

$(function(){
  //@prepros-include code1.js
  //@prepros-include code2.js
  //@prepros-include code3.js
  //@prepros-include code3.js
  ...
});

Is that somehow possible, or have you any other solution how to concatenate a lot of js-fragments which would be bound inside jquery $(function(){...}); wrapper?

[edit] Ps. I don't want to write $(function(){...}); inside of each partial-file.

Dariusz Sikorski
  • 4,309
  • 5
  • 27
  • 44
  • Your best solution is probably something like [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/). These allow you to build modular JavaScript for use on the web. – Jon Surrell Nov 16 '15 at 10:57

1 Answers1

1

Well if you use google the first link wil be this one of jquery home page But if you want to include in your js file other js files use this.

$.getScript( "ajax/test.js" )
  .done(function( script, textStatus ) {
    console.log( textStatus );
  })
  .fail(function( jqxhr, settings, exception ) {
    alert("No file found");
});

ofcourse you can easily easy a line like this.

$.getScript( "ajax/test.js" );
Wim Pruiksma
  • 588
  • 5
  • 19
  • 1
    I'm interested in concatenation files into one output code, in this case Ajax requests would affect page loading time, and won't work on file:/// protocol, which in very few cases is a useful thing as it doesn't require setting up a webserver. Ps. if I would decide for ajax solution I'd use Require.js instead of jquery http://requirejs.org/ – Dariusz Sikorski Nov 16 '15 at 11:17