Radishok_LazyJs - Version 0.0.0.4

Version Notes

Added the "disabled on pages" option

Download this release

Release Info

Developer Denis Derbenyov
Extension Radishok_LazyJs
Version 0.0.0.4
Comparing to
See all releases


Code changes from version 0.0.0.3 to 0.0.0.4

app/code/local/Radishok/LazyJs/Model/Observer.php CHANGED
@@ -21,6 +21,7 @@
21
  class Radishok_LazyJs_Model_Observer extends Varien_Object{
22
  const MODULE_ENABLED = 'radishoklazyjs/settings/active';
23
  const DEFER_JS = 'radishoklazyjs/settings/defer_js';
 
24
  protected $_allJs = array();
25
  protected $_jsScripts = array();
26
 
@@ -83,6 +84,7 @@ class Radishok_LazyJs_Model_Observer extends Varien_Object{
83
  $script['inline'] = true;
84
  $script['text'] = $matches[2];
85
  } elseif(strpos($matches[1],' src=')) {
 
86
  preg_match('#(.*?)src="(.*)"#is',$matches[1],$src);
87
  $script['inline'] = false;
88
  $script['src'] = $src[2];
@@ -95,22 +97,25 @@ class Radishok_LazyJs_Model_Observer extends Varien_Object{
95
  }
96
 
97
  public function afterToHtml($observer) {
98
- if(Mage::getStoreConfig(self::MODULE_ENABLED)){
99
- if ($observer->getBlock()->getNameInLayout() == 'root'){
100
- $object = $observer->getTransport();
101
- if(Mage::getStoreConfig(self::DEFER_JS)){
102
- $calback = array($this, '_replaceCallbackDefer');
103
- } else {
104
- $calback = array($this, '_replaceCallback');
105
- }
106
- $result = preg_replace_callback(
107
- array('#<script(.*?)>(.*?)</script>#is', '#<script(.*?)/>#is'),
108
- $calback, $object->getHtml()
109
- );
110
- $script = $this->_getResultScript();
111
- $result = str_replace('</body>', $script.'</body>', $result);
112
- $object->setHtml($result);
113
  }
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
  }
116
  }
21
  class Radishok_LazyJs_Model_Observer extends Varien_Object{
22
  const MODULE_ENABLED = 'radishoklazyjs/settings/active';
23
  const DEFER_JS = 'radishoklazyjs/settings/defer_js';
24
+ const DISABLED_PAGES = 'radishoklazyjs/settings/disabled_pages';
25
  protected $_allJs = array();
26
  protected $_jsScripts = array();
27
 
84
  $script['inline'] = true;
85
  $script['text'] = $matches[2];
86
  } elseif(strpos($matches[1],' src=')) {
87
+ $src = '';
88
  preg_match('#(.*?)src="(.*)"#is',$matches[1],$src);
89
  $script['inline'] = false;
90
  $script['src'] = $src[2];
97
  }
98
 
99
  public function afterToHtml($observer) {
100
+ if ($observer->getBlock()->getNameInLayout() == 'root' && Mage::getStoreConfig(self::MODULE_ENABLED)){
101
+ $request = Mage::app()->getRequest();
102
+ $e = $request->getRequestString();
103
+ $disabled_pages = explode('\n',Mage::getStoreConfig(self::DISABLED_PAGES));
104
+ $object = $observer->getTransport();
105
+ if(in_array($e,$disabled_pages) || strripos($object->getHtml(),'</body>')===false){
106
+ return;
 
 
 
 
 
 
 
 
107
  }
108
+ if(Mage::getStoreConfig(self::DEFER_JS)){
109
+ $calback = array($this, '_replaceCallbackDefer');
110
+ } else {
111
+ $calback = array($this, '_replaceCallback');
112
+ }
113
+ $result = preg_replace_callback(
114
+ array('#<script(.*?)>(.*?)</script>#is', '#<script(.*?)/>#is'),
115
+ $calback, $object->getHtml()
116
+ );
117
+ $script = $this->_getResultScript();
118
+ $object->setHtml(str_replace('</body>', $script.'</body>', $result));
119
  }
120
  }
121
  }
app/code/local/Radishok/LazyJs/etc/config.xml CHANGED
@@ -22,7 +22,7 @@
22
  <config>
23
  <modules>
24
  <Radishok_LazyJs>
25
- <version>0.0.0.3</version>
26
  </Radishok_LazyJs>
27
  </modules>
28
  <global>
22
  <config>
23
  <modules>
24
  <Radishok_LazyJs>
25
+ <version>0.0.0.4</version>
26
  </Radishok_LazyJs>
27
  </modules>
28
  <global>
app/code/local/Radishok/LazyJs/etc/system.xml CHANGED
@@ -45,7 +45,7 @@
45
  <show_in_store>1</show_in_store>
46
  <fields>
47
  <active>
48
- <label>Module Enabled(version: 0.0.0.3)</label>
49
  <frontend_type>select</frontend_type>
50
  <source_model>adminhtml/system_config_source_yesno</source_model>
51
  <sort_order>10</sort_order>
@@ -83,6 +83,15 @@
83
  ]]>
84
  </comment>
85
  </defer_js>
 
 
 
 
 
 
 
 
 
86
  </fields>
87
  </settings>
88
  </groups>
45
  <show_in_store>1</show_in_store>
46
  <fields>
47
  <active>
48
+ <label>Module Enabled(version: 0.0.0.4)</label>
49
  <frontend_type>select</frontend_type>
50
  <source_model>adminhtml/system_config_source_yesno</source_model>
51
  <sort_order>10</sort_order>
83
  ]]>
84
  </comment>
85
  </defer_js>
86
+ <disabled_pages>
87
+ <label>Disabled on pages</label>
88
+ <frontend_type>textarea</frontend_type>
89
+ <sort_order>30</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ <comment><![CDATA[Each request path on new line<br/>Example: <br/>/contacts<br/>/checkout/cart/]]></comment>
94
+ </disabled_pages>
95
  </fields>
96
  </settings>
97
  </groups>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Radishok_LazyJs</name>
4
- <version>0.0.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This Extension will speed up frontend rendering by placing JavaScript at the bottom of the page </summary>
10
  <description>When you put your JavaScript at the top of the page, the browser will start loading your JS files before the markup, images and text. And since browsers load JavaScript synchronously, nothing else will load while the JavaScript is loading. So there will be a timeframe of a few seconds where the user will see a blank page, while the JavaScript is loading. On the other hand, if you place your JavaScript at the bottom of the page, the user will see the page loading first, and after that the JavaScript will load in the background. So if for example your CSS &amp; HTML takes 5 seconds to load, and your JavaScript takes another 5 seconds, putting our JavaScript on the top of the page will give the user a &#x201C;perceived&#x201D; loading time of 10 seconds, and putting it on the bottom will give a &#x201C;perceived&#x201D; loading time of 5 seconds.</description>
11
- <notes>Improved deferjs option</notes>
12
  <authors><author><name>Denis Derbenyov</name><user>radishok</user><email>ddenisiy@gmail.com</email></author></authors>
13
- <date>2014-08-08</date>
14
- <time>21:12:49</time>
15
- <contents><target name="magelocal"><dir name="Radishok"><dir name="LazyJs"><dir name="Model"><file name="Observer.php" hash="f95d47d49eff7b2a57a5817515ddf59e"/></dir><dir name="etc"><file name="config.xml" hash="6b309e582c453d04cea091075ea42e8b"/><file name="system.xml" hash="7cca90b79d0b4d73b11aa72bf371b240"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Radishok_LazyJs.xml" hash="594198ce4094a6ac5c47c7d99f36d5d3"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Radishok_LazyJs</name>
4
+ <version>0.0.0.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>This Extension will speed up frontend rendering by placing JavaScript at the bottom of the page </summary>
10
  <description>When you put your JavaScript at the top of the page, the browser will start loading your JS files before the markup, images and text. And since browsers load JavaScript synchronously, nothing else will load while the JavaScript is loading. So there will be a timeframe of a few seconds where the user will see a blank page, while the JavaScript is loading. On the other hand, if you place your JavaScript at the bottom of the page, the user will see the page loading first, and after that the JavaScript will load in the background. So if for example your CSS &amp; HTML takes 5 seconds to load, and your JavaScript takes another 5 seconds, putting our JavaScript on the top of the page will give the user a &#x201C;perceived&#x201D; loading time of 10 seconds, and putting it on the bottom will give a &#x201C;perceived&#x201D; loading time of 5 seconds.</description>
11
+ <notes>Added the "disabled on pages" option</notes>
12
  <authors><author><name>Denis Derbenyov</name><user>radishok</user><email>ddenisiy@gmail.com</email></author></authors>
13
+ <date>2014-08-25</date>
14
+ <time>14:37:15</time>
15
+ <contents><target name="magelocal"><dir name="Radishok"><dir name="LazyJs"><dir name="Model"><file name="Observer.php" hash="9b82f4c35eb1c8f703f31de4daeabd01"/></dir><dir name="etc"><file name="config.xml" hash="239bed014512600283b4540af23852ed"/><file name="system.xml" hash="77d2f9bae58fc80ad8bf53c92bf81a06"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Radishok_LazyJs.xml" hash="594198ce4094a6ac5c47c7d99f36d5d3"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>