array(), 'last' => array(), ); private $dontmove = array( 'document.write', 'html5.js', 'show_ads.js', 'google_ad', 'histats.com/js', 'statcounter.com/counter/counter.js', 'ws.amazon.com/widgets', 'media.fastclick.net', '/ads/', 'comment-form-quicktags/quicktags.php', 'edToolbar', 'intensedebate.com', 'scripts.chitika.net/', '_gaq.push', 'jotform.com/', 'admin-bar.min.js', 'GoogleAnalyticsObject', 'plupload.full.min.js', 'syntaxhighlighter', 'adsbygoogle', 'gist.github.com', '_stq', 'nonce', 'post_id', 'data-noptimize', 'logHuman', ); private $domove = array( 'gaJsHost', 'load_cmc', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'tiny_mce.js', 'tinyMCEPreInit.go', ); private $domovelast = array( 'addthis.com', '/afsonline/show_afs_search.js', 'disqus.js', 'networkedblogs.com/getnetworkwidget', 'infolinks.com/js/', 'jd.gallery.js.php', 'jd.gallery.transitions.js', 'swfobject.embedSWF(', 'linkwithin.com/widget.js', 'tiny_mce.js', 'tinyMCEPreInit.go', ); public $cdn_url = ''; private $jsremovables = array(); // Reads the page and collects script tags. public function read($options) { $excludeJS = $options['js_exclude']; if ('' !== $excludeJS) { if (is_array($excludeJS)) { if (($removeKeys = array_keys($excludeJS, 'remove')) !== false) { foreach ($removeKeys as $removeKey) { unset($excludeJS[$removeKey]); $this->jsremovables[] = $removeKey; } } $exclJSArr = array_keys($excludeJS); } else { $exclJSArr = array_filter(array_map('trim', explode(',', $excludeJS))); } $this->dontmove = array_merge($exclJSArr, $this->dontmove); } // noptimize me. $this->content = $this->hide_noptimize($this->content); // Save IE hacks. $this->content = $this->hide_iehacks($this->content); // comments. $this->content = $this->hide_comments($this->content); // Get script files. if (preg_match_all('##Usmi', $this->content, $matches)) { foreach ($matches[0] as $tag) { // only consider script aggregation for types whitelisted in should_aggregate-function. $should_aggregate = $this->should_aggregate($tag); if (!$should_aggregate) { continue; } if (preg_match('#]*src=("|\')([^>]*)("|\')#Usmi', $tag, $source)) { // non-inline script. main part of changing script if ($this->isremovable($tag, $this->jsremovables)) { $this->content = str_replace($tag, '', $this->content); continue; } $origTag = $tag; $newTag = $tag; // non-mergeable script (excluded or dynamic or external). if ($this->isExcluded($newTag)) { $newTag = str_replace('src=', 'data-pagespeed-no-defer src=', $tag); $this->content = str_replace($origTag, $newTag, $this->content); } } } return true; } // No script files, great ;-) return false; } /** * Determines wheter a certain `