#21633 closed task (blessed) (fixed)
Switch to min.js convention
Reported by: | nbachiyski | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Most of the projects I use these days use min.js
for the filenames of their minified files. This does a couple of good things:
- Sets some expectations in developers looking at the files. Numerous times I've forgotten for our
.dev.js
convention and have opened the minified files in a text editor.
- Sets some expectations in some software tools. For example,
ack
automatically skips searchingmin.js
files.
Possible problems: I don't see any.
Plugins should be using wp_enqueue_script()
and changing paths shouldn't be a problem. Browser caches of developers shouldn't be a huge problem, either.
If everybody is fine with the change, I'd be happy to volunteer and steer the transition, including the patches.
Attachments (1)
Change History (17)
#2
@
12 years ago
wp_enqueue_script() already has too many parameters, IMO. We should switch to named arguments if we want to add $dev, or $min.
#3
follow-ups:
↓ 4
↓ 6
@
12 years ago
- Milestone changed from Awaiting Review to 3.5
- Type changed from feature request to task (blessed)
koopersmith and I were discussing this just yesterday. I strongly agree with this. It's also easy to do, and I don't think a patch would even be needed (beyond a few lines in script-loader), as most of the magic here is simply getting the svn copy commands right so history doesn't get all screwed up, like what happened in [10291].
Though implied, just going to state we should do this for CSS as well.
Plugins should be using wp_enqueue_script() and changing paths shouldn't be a problem.
Not only that, but no developer would really ever be referencing .dev.js directly. So if they were referencing .js directly, they'll simply go from using the minified to the unminified scripts.
With this I would also give a vote for a new arg $dev in WP_SCRIPTS/WP_STYLES API which controls minified files.
I like this, though I'm not sure how I feel about a new argument on wp_register/enqueue_script. There are probably three or four proposed new parameters for this function across Trac. I think it is time to convert $in_footer = false to an array of extra arguments, so 'footer' => true and the like. (As scribu just recommended as well.)
#4
in reply to:
↑ 3
@
12 years ago
Replying to nacin:
koopersmith and I were discussing this just yesterday. I strongly agree with this.
Likewise. Nikolay hit the main points on the head — I think this is an easy win.
#6
in reply to:
↑ 3
;
follow-up:
↓ 7
@
12 years ago
Replying to nacin:
With this I would also give a vote for a new arg $dev in WP_SCRIPTS/WP_STYLES API which controls minified files.
I like this, though I'm not sure how I feel about a new argument on wp_register/enqueue_script. There are probably three or four proposed new parameters for this function across Trac. I think it is time to convert $in_footer = false to an array of extra arguments, so 'footer' => true and the like. (As scribu just recommended as well.)
Converting $in_footer to an array of extra arguments seems rather arbitrary to me, since only $handle and $src are required. I was thinking more along these lines:
wp_register_script( $handle, $src, array( ... ) );
#7
in reply to:
↑ 6
;
follow-up:
↓ 10
@
12 years ago
Replying to scribu:
That's not going to work well. Currently:
wp_register_script( $handle, $src, $deps = array(), ... );
so we would be fishing in the $deps array for other args.
#8
in reply to:
↑ 1
@
12 years ago
Replying to ocean90:
With this I would also give a vote for a new arg $dev in WP_SCRIPTS/WP_STYLES API which controls minified files. If $dev is defined in
wp_register_script
and SCRIPT_DEBUG is true load the minified file.
You mean the non-minified file.
The same could probably be accomplished by looking for .min.js
or .min.css
in the registered script or stylesheet and expecting there are non-minified versions without the suffix.
#10
in reply to:
↑ 7
@
12 years ago
Replying to azaozz:
so we would be fishing in the $deps array for other args.
Yeah, you're right. So maybe after it:
wp_register_script( $handle, $src, $deps = array(), $args = array() );
The same could probably be accomplished by looking for .min.js or .min.css in the registered script or stylesheet and expecting there are non-minified versions without the suffix.
Yes, but only if we ship non-minified versions of all the third-party libs, like jQuery, which we don't.
#11
@
12 years ago
Notes on the implementation:
The goal is to retain the history for all files. Here is what I came up with:
svn cp xxx.js xxx.min.js svn rm xxx.js svn mv xxx.dev.js xxx.js
svn
is smart enough to notice we are replacing files. Here is the svn st
:
A + xxx.min.js R + xxx.js D xxx.dev.js
In my testing this retains the history for all of the files. I would love if some of your tests on their setups to see if that's true.
Here's a dirty script to do all the needed changes:
find . -name '*.dev.js' -print0 | xargs -0 perl -e 'foreach(@ARGV){ $dev=$_; $min=$js=$dev; $js=~s/\.dev\././; $min=~s/\.dev\./.min./; system("svn cp $js $min"); system("svn rm $js"); system("svn mv $dev $js"); }'
#12
@
12 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [21592]:
#13
@
12 years ago
Thanks for the legwork, Nikolay. Rather than svn cp; svn rm; svn mv
, it only required svn mv; svn mv
. This makes SVN consider the file "replaced." If you're interested, http://www.red-bean.com/pipermail/svnbook-dev/2006-January/001527.html.
With this I would also give a vote for a new arg $dev in WP_SCRIPTS/WP_STYLES API which controls minified files. If $dev is defined in
wp_register_script
and SCRIPT_DEBUG is true load the non-minified file. This would reduce the checks in a plugin.