Gulp: Work in progress, newbie needs support please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

If you're looking at further improving load times, take a look at this http://betterexplained.com/articles/how ... mpression/
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

Just be careful not to fall into the trap of micro-optimization.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Gulp: Work in progress, newbie needs support please

Post by simonmlewis »

No. Minifying it would actually use more space as you'd have two copies of the file; one minified, one not.
Does this happen with CSS too?

I'm a bit lost again as to how to use Gulp for minifying.
I assume you use it to reduce it all down, and then you uplod that file INSTEAD of the old (larger) CSS file.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

Yes, that's right. The benefit isn't to reduce disk space used, which would be a very marginal gain, but to reduce the size of the payload the client is pulling down, thereby improving load times. As PHP isn't sent to the client, minifying PHP provides no benefit. Gzipping the resultant HTML can.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Gulp: Work in progress, newbie needs support please

Post by simonmlewis »

So what do I do with the contents of my dist folder?
So I use those files, instead of the current CSS files?

As the way I read you rmessage, I have to upload BOTH files for some reason.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

simonmlewis wrote:So what do I do with the contents of my dist folder?
So I use those files, instead of the current CSS files?
Yes. Have one directory for human-readable, easily editable files, and one containing the minified versions that you actually use in your site.
simonmlewis wrote:As the way I read you rmessage, I have to upload BOTH files for some reason.
You don't need to. Doesn't really matter one way or the other. What's important is that the client be pulling down the minified files.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Gulp: Work in progress, newbie needs support please

Post by simonmlewis »

So locally, I run Gulp which minifies CSS and JS (so far), and I edit Gulp first I guess to make sure it uses the same filenames too! (easier).

Then I upload only the dist folder files to their relevant places on the live server.
Thus not specifically reducing file sizes, but because there is less to "read" in the files, they take less time to load.
I suppose to do a "manual" version of this minifying, I should reduce the white space where poss in my index.php file and others.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

simonmlewis wrote:So locally, I run Gulp which minifies CSS and JS
Right
simonmlewis wrote:and I edit Gulp first I guess to make sure it uses the same filenames too! (easier).
I suppose, if you like. Personally, I'd just edit site.js and set my script src to site.min.js and so forth.
simonmlewis wrote:Thus not specifically reducing file sizes, but because there is less to "read" in the files, they take less time to load.
No, the minified files are measurably smaller. A space is still a character, as is a tab.
simonmlewis wrote:I suppose to do a "manual" version of this minifying, I should reduce the white space where poss in my index.php file and others.
No. Keep your files legible. You're going to need to go back and edit them. As I have already stated, minifying PHP will yield precisely zero benefit. Set up Gzip compression in Apache if you want to reduce the size of what's being sent over the wire.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Gulp: Work in progress, newbie needs support please

Post by simonmlewis »

I understand about the PHP, as if you have aton of code, and then "echo 'hello'", the "hello" is all that is actually loaded up.
In the dist folder are two js files. all.js and all.min.js. Which is the one that I use?

reading the gulp file, it's all.min.js.

Code: Select all

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Gulp: Work in progress, newbie needs support please

Post by Celauran »

simonmlewis wrote:reading the gulp file, it's all.min.js.
Yes, that's right.
Post Reply