Hacker News new | ask | show | jobs
by eta_carinae 4970 days ago
There is no easy way to include .js file that are stored on your server.
3 comments

I've been using PHP Minify [1], a simple script to concatenate, minify, and send out my backbonejs project.

Works well.

[1] - https://github.com/mrclay/minify

That doesn't address my point, which was about includes at runtime of .js files.

The reason why you see big .js files is that it's not easy to split your code in a.js and have it include b.js from the server.

You might look into preprocessing tools like grunt, which are designed for precisely this
huh? post-process them with something like Jammit. Or just `cat file file file file > final.js` and shove it through a minifier.
Depends what your definition of "easy" is. It's harder in JS than in most languages.
Why is it harder? Concatenating the files is literally all that's necessary, as long as you build them intelligently:

  (function() { /* your code */})()
I'd argue that's significantly easier than most languages. But still - this can easily be a single bash line in your deploy script, or you can run `make` before copying the files over FTP. It's not easy, it's trivial.
Why is it harder?

Things like "as long as you build them intelligently", "bash", and "deploy script".

>There is no easy way to include .js file that are stored on your server.

So lets assume you have a totally-static website. That involves copying files over e.g. FTP at worst. So you have an FTP application, editing tools, etc. How unlikely is it that either A) the tools don't offer JS minification, or B) you're using flat text editors, and can't find someone who can write `cat /.js > all.js` or apparently the Windows equivalent `copy /b file+file+file all.js` in an executable text file? Then it's a double-click and drag the all.js file over.

Remember, we already have multiple source files which are included everywhere or this wouldn't be a debating point. So your files must be include-able in every page, which are either order-agnostic or must always be in the same order. Either you maintain that by hand, or you run one of those scripts or you use your editing application. Is editing every file by hand easier or harder than a single double-click?