0

I'm trying to organize my Javascript code and Require.js seems to be the ticket, but it looks like the optimization tool can only be used with Node (NOTE: I know it says the browser can be used too, but it isn't recommended).

If I'm using PHP, is there any way for me to optimize my Javascript?

My current stack: PHP, Slim 3.0, Twig and Webix

4
  • I've edited out the part of your question that was primarily opinion-based and that made your question too broad. Commented Apr 6, 2017 at 17:15
  • Is this a new feature? It's nice. Teach me the ways. Thanks Commented Apr 6, 2017 at 19:32
  • It doesn't matter that you're running on PHP. The optimiser is not run on the application server, but during the build process on your dev machine. Commented Apr 7, 2017 at 13:02
  • And installing Node on a dev machine is trivial. Commented Apr 7, 2017 at 16:47

1 Answer 1

1

You do not have to use r.js to optimize your AMD modules. Any tool that knows how to read AMD modules and how to produce a bundle from them could be used instead of r.js. I don't know if such a tool exists that is implemented in PHP.

If you are going to use r.js then you must have a JavaScript virtual machine that will run its code. r.js only supports Node, Rhino, Nashorn, or the browser. This is a limited list because r.js needs to be able to read files, and how to do this varies from platform to platform. (This also explains why browser usage is not generally recommended: the limitations in the browser are such that it can only be viable for restricted cases and not for general optimization.)

I'm not seeing the need for Node as being particularly onerous. The first projects I used RequireJS with were for applications backed by Django, which is a Python-based web framework. That's similar to your own situation.

Sign up to request clarification or add additional context in comments.

Comments

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.