1

Is their any way with which we can merge only JS files that are used in Front-end and keep JS files untouched that are used in backend( for admin panel).

I have checked my site with Google Pagespeed and found that my page has 2 blocking script resources. In order to solve this is have simply added "async" to my tag. After this my Pagespeed rank was increased, but on testing i found that on Admin Panel none of grid's select all,select page, select visible action is working as it was throwing some JS Error.

I believe that Some files in admin panel must be using Inline Js that must be dependent on some external file, because of asynchronous Js loading inline Js is not abale to get its desired function and hence resulted in error.

Can any one please guide me how i can overcome this issue.

4

You just want to merge JS in the frontend but not admin? This is simple! Go to system -> configuration in admin. Set the store scope to default, turn developer -> javascript settings -> merge javascript off and save. Then set your scope to the front end store view and repeat but turn merge javascript on.

| improve this answer | |
  • This one is quite better and don't need to do any core code overriding. Thanks – rbncha Jun 29 '15 at 19:34
  • I logged in just to give a +, how did I not think about this earlier. – Aivis Zvezdovs Nov 10 '16 at 19:12
1

Here it's solution: Copy Head.php from /app/code/core/Mage/Page/Block/Html to /app/code/local/Mage/Page/Block/Html and go to line number: 204 replace from:

$html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n",
                empty($items['js']) ? array() : $items['js'],
                empty($items['skin_js']) ? array() : $items['skin_js'],
                $shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null
            );

to:

if (Mage::app()->getStore()->isAdmin()) {
                $html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n",
                    empty($items['js']) ? array() : $items['js'],
                    empty($items['skin_js']) ? array() : $items['skin_js'],
                    $shouldMergeJs ? null : null
                );
            } else{
                $html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript"  src="%s"%s></script>' . "\n",
                    empty($items['js']) ? array() : $items['js'],
                    empty($items['skin_js']) ? array() : $items['skin_js'],
                    $shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null
                );
            }
| improve this answer | |
  • There is no need to modify code to achieve this. You can do it by changing configuration in admin. – Andrew Kett Jun 29 '15 at 20:41
  • @andrewkett: Yes you can, but from magento original code css & js of admin also merged, this will cause error in admin with some extensions. So I have wrote code & use admin condition, using this code only frontend css & js are merge not admin side. – Rahul Dadhich Jun 30 '15 at 5:28
1

Another way is to tell Google Pagespeed not to touch certain files or folders: https://developers.google.com/speed/pagespeed/module/restricting_urls

Even more advance, you can group files into, well, groups. An example:

<action method="addItem"><type>skin_js</type><name>js/jquery.js</name><group>jquery</group></action>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.