Meigee_JavascriptDefer - Version 1.0.0

Version Notes

Version 1.0 of the extension.

Download this release

Release Info

Developer Meigee Sp.Z.o.o
Extension Meigee_JavascriptDefer
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Meigee/JavascriptDefer/Helper/Data.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Javascript Defer
4
+ * @copyright Copyright (c) 2010-2015 MeigeeTeam. (http://www.meigeeteam.com)
5
+ */
6
+ ?>
7
+ <?php
8
+ class Meigee_JavascriptDefer_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {}
app/code/community/Meigee/JavascriptDefer/Model/Observer/Html.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Javascript Defer
4
+ * @copyright Copyright (c) 2010-2015 MeigeeTeam. (http://www.meigeeteam.com)
5
+ */
6
+ ?>
7
+ <?php
8
+ class Meigee_JavascriptDefer_Model_Observer_Html
9
+ {
10
+ public function replaceJs($observer)
11
+ {
12
+ if (!Mage::app()->getRequest()->getParam('isAjax')
13
+ && (bool)Mage::getStoreConfig('meigee/js/enable_javascriptDefer'))
14
+ {
15
+ $response = $observer->getData('response');
16
+ $html = $response->getBody();
17
+ $js_arr = array();
18
+
19
+ $pattern = "/((<\!--\[if lt IE(.*)<\!\[endif\]-->)|(<script*(.*)<\/script>))/isU";
20
+ preg_match_all($pattern, $html, $matches);
21
+ $base_adr = str_replace(array('https://','http://'), '', Mage::getConfig()->substDistroServerVars('{{base_url}}'));
22
+ $base_adr_arr = explode('/', $base_adr);
23
+ $base_adr = $base_adr_arr[0];
24
+
25
+ $is_use_ext_sources = (bool)Mage::getStoreConfig('meigee/js/enable_javascriptDefer_external_sources');
26
+ foreach($matches[0] AS $js)
27
+ {
28
+ if (false !== strpos($js, '<script'))
29
+ {
30
+ $html = str_replace($js, '', $html);
31
+ preg_match('/<* src=(("|\')[^"]*("|\'))>/i',$js, $src_arr);
32
+ if ($is_use_ext_sources && $src_arr && false === strpos($src_arr[1], $base_adr))
33
+ {
34
+ $js_arr[] = '
35
+ <script type="text/javascript">
36
+ //<![CDATA[
37
+ var script =document.createElement("script");
38
+ script.src = "'.trim($src_arr[1], "'\"").'";
39
+ script.type = "text/javascript";
40
+ document.getElementsByTagName("head")[0].appendChild(script);
41
+ //]]>
42
+ </script>';
43
+ }
44
+ else
45
+ {
46
+ $js_arr[] = trim($js);
47
+ }
48
+ }
49
+ }
50
+ if (!empty($js_arr))
51
+ {
52
+ $html = preg_replace(array('/\r/', '/\n{2,}/') , '', $html);
53
+ $js_str = implode("\n", $js_arr);
54
+ $body_text = '</body>';
55
+ $html = str_replace($body_text, $js_str.$body_text, $html);
56
+ $response->setBody($html);
57
+ }
58
+ }
59
+ }
60
+ }
61
+
app/code/community/Meigee/JavascriptDefer/etc/config.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ *
5
+ * @package Javascript Defer
6
+ * @copyright Copyright (c) 2010-2015 MeigeeTeam. (http://www.meigeeteam.com)
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Meigee_JavascriptDefer>
12
+ <version>0.0.1</version>
13
+ </Meigee_JavascriptDefer>
14
+ </modules>
15
+ <global>
16
+ <helpers>
17
+ <JavascriptDefer>
18
+ <class>Meigee_JavascriptDefer_Helper</class>
19
+ </JavascriptDefer>
20
+ </helpers>
21
+ <models>
22
+ <javascriptDefer>
23
+ <class>Meigee_JavascriptDefer_Model</class>
24
+ </javascriptDefer>
25
+ </models>
26
+ </global>
27
+ <frontend>
28
+ <events>
29
+ <http_response_send_before>
30
+ <observers>
31
+ <javascriptDefer>
32
+ <type>singleton</type>
33
+ <class>javascriptDefer/observer_html</class>
34
+ <method>replaceJs</method>
35
+ </javascriptDefer>
36
+ </observers>
37
+ </http_response_send_before>
38
+ </events>
39
+ </frontend>
40
+ <adminhtml>
41
+ <acl>
42
+ <resources>
43
+ <admin>
44
+ <children>
45
+ <system>
46
+ <children>
47
+ <config>
48
+ <children>
49
+ <meigee>
50
+ <title>General Optmization</title>
51
+ </meigee>
52
+ </children>
53
+ </config>
54
+ </children>
55
+ </system>
56
+ </children>
57
+ </admin>
58
+ </resources>
59
+ </acl>
60
+ </adminhtml>
61
+ <default>
62
+ <meigee>
63
+ <js>
64
+ <enable_javascriptDefer>0</enable_javascriptDefer>
65
+ <enable_javascriptDefer_external_sources>1</enable_javascriptDefer_external_sources>
66
+ </js>
67
+ </meigee>
68
+ </default>
69
+ </config>
app/code/community/Meigee/JavascriptDefer/etc/system.xml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <!--
3
+ /**
4
+ *
5
+ * @package Javascript Defer
6
+ * @copyright Copyright (c) 2010-2015 MeigeeTeam. (http://www.meigeeteam.com)
7
+ */
8
+ -->
9
+ <tabs>
10
+ <meigee_extensions_tab translate="label" module="JavascriptDefer">
11
+ <label>Meigee Extensions</label>
12
+ <sort_order>100</sort_order>
13
+ </meigee_extensions_tab>
14
+ </tabs>
15
+ <sections>
16
+ <meigee translate="label" module="JavascriptDefer">
17
+ <label>Javascript Defer</label>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ <tab>meigee_extensions_tab</tab>
23
+ <groups>
24
+ <js translate="label">
25
+ <label>Js</label>
26
+ <frontend_type>text</frontend_type>
27
+ <sort_order>2</sort_order>
28
+ <show_in_default>1</show_in_default>
29
+ <show_in_website>1</show_in_website>
30
+ <show_in_store>1</show_in_store>
31
+ <fields>
32
+ <enable_javascriptDefer translate="label">
33
+ <label>Enable JavascriptDefer</label>
34
+ <frontend_type>Select</frontend_type>
35
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
36
+ <sort_order>1</sort_order>
37
+ <comment>Enable JavascriptDefer</comment>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ </enable_javascriptDefer>
42
+ <enable_javascriptDefer_external_sources translate="label">
43
+ <label>Apply for external scripts</label>
44
+ <frontend_type>Select</frontend_type>
45
+ <source_model>adminhtml/system_config_source_yesno</source_model>
46
+ <sort_order>2</sort_order>
47
+ <comment>If your scripts are loaded from the external sources, and need to be loaded before HTML content, then set No.</comment>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>1</show_in_website>
50
+ <show_in_store>1</show_in_store>
51
+ <depends>
52
+ <enable_javascriptDefer>1</enable_javascriptDefer>
53
+ </depends>
54
+ </enable_javascriptDefer_external_sources>
55
+ </fields>
56
+ </js>
57
+ </groups>
58
+ </meigee>
59
+ </sections>
60
+ </config>
app/etc/modules/Meigee_JavascriptDefer.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ /**
3
+ *
4
+ * @package Javascript Defer
5
+ * @copyright Copyright (c) 2010-2015 MeigeeTeam. (http://www.meigeeteam.com)
6
+ */
7
+ -->
8
+ <config>
9
+ <modules>
10
+ <Meigee_JavascriptDefer>
11
+ <active>true</active>
12
+ <codePool>community</codePool>
13
+ </Meigee_JavascriptDefer>
14
+ </modules>
15
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Meigee_JavascriptDefer</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Javascript Defer Extension allows defer parsing of JavaScript that increases performance of your store.</summary>
10
+ <description>Defer parsing of JavaScript&#xD;
11
+ Speeds up the store loading&#xD;
12
+ Reduces the server loading&#xD;
13
+ Increases rating of your store in GTmetrix&#xD;
14
+ Easy configuration</description>
15
+ <notes>Version 1.0 of the extension.</notes>
16
+ <authors><author><name>Meigee Sp.Z.o.o</name><user>Meigee</user><email>nick@meigeeteam.com</email></author></authors>
17
+ <date>2015-11-05</date>
18
+ <time>11:32:01</time>
19
+ <contents><target name="magecommunity"><dir name="Meigee"><dir name="JavascriptDefer"><dir name="Helper"><file name="Data.php" hash="c2f775ad646d7746ab1b5fc532c7376b"/></dir><dir name="Model"><dir name="Observer"><file name="Html.php" hash="d6a12a8136769bc3cd2a517a1156eef1"/></dir></dir><dir name="etc"><file name="config.xml" hash="4c49fe0eee6c6bbce9866d406bf4f208"/><file name="system.xml" hash="a71dc4c752b1cbab45d90e3268bf53e4"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Meigee_JavascriptDefer.xml" hash="2b5eadeb34055dd90936edd3a7f9a705"/></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.4.0</min><max>5.5.9</max></php></required></dependencies>
22
+ </package>