r94334 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94333‎ | r94334 | r94335 >
Date:10:20, 12 August 2011
Author:dantman
Status:ok
Tags:
Comment:
Use a regex when checking for external urls. It's concise and DRY, less prone to bugs like "Whoops I got that hardcoded length int wrong and created a condition that'll never be true",... and it's 4 time faster ;)
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -1071,7 +1071,7 @@
10721072 // Allow calling with an external script or single dependency as a string
10731073 if ( typeof modules === 'string' ) {
10741074 // Support adding arbitrary external scripts
1075 - if ( modules.substr( 0, 7 ) === 'http://' || modules.substr( 0, 8 ) === 'https://' || modules.substr( 0, 2 ) === '//' ) {
 1075+ if ( /^(https?:)?\/\//.test( modules ) ) {
10761076 if ( type === 'text/css' ) {
10771077 $( 'head' ).append( $( '<link/>', {
10781078 rel: 'stylesheet',

Status & tagging log