Magento Adminhtml and Relative Links to Static Resources

Relative links in URLs allow you to only specify the path to an resource that is in the same or subfolder of the current folder. Lets say the current page you are on is http://example.com/test/ and you want to reference an image at http://example.com/test/image.jpg. You could put the full http://example.com/test/image.jpg in the src attribute of the img tag, or you could use just image.jpg instead. This works well when you are not sure what the directory path is the parent directory of your code. However, it can cause some issues when your code is moved to another location, but some resources are not moved, such as image.jpg.

Magento Adminhtml

Magento’s Adminhtml, or administration backend goes through a completely different route in the app/Mage.php code to enable you to control the menu, products, and content of your site, among other things. Many eCommerce sites using Magento need some aspect of the administration backend customized to handle the unique workflow for the business. However, there are some occasions where this can cause some unintended consequences.

When customizing the administration backend for Magento, there are some cases where you may need to include a third party library to achieve the desired result. One thing that many of these libraries do is reference all of their resources with relative links. If, in the process of including the third party library, you neglect to include the resources referenced in the JavaScript or CSS, then it will cause a 404 error to occur when accessing the resources.

When you factor in that only the URLs that are configured for the administration backend load the backend code, and all others, including 404 not found errors load the frontend code and error pages to help your users find their way, you may start to see some performance issues. I have seen some sites with two such resources with 404 errors attempt to be loaded on every administration backend page load. Not only does it cause the web server to load all of the frontentd .phtml files necessary to display the 404 error page, but it also incurs all the same database access calls that are required as well. When accessing the administration backend of this particular site with the 404 resources included, there is a definite delay in the loading of the page. Simply removing the references to these resources that do not exist or correcting these refereces makes the page load extremely quickly, as one would expect.

Related Posts

Apr 17, 2014
2 minutes

MySQL Deadlocks with Magento

One of the things that Magento, and specifically the Zend Framework provide developers is the ability to not have to think about database details as it should just handle all that for you. When it becomes obvious that there is a problem somehow with the production database getting some sort of SQL errors, its time for the developers to start caring about the implementation and architecture details of the database.

Mar 29, 2014
2 minutes

301 Redirecting in Varnish

In Magento, you can set your secure and non-secure URLs explicitly. This works as expected in most cases, but can cause some issues when you have to specify full URLs or need to make any AJAX requests. When using the Nexcess Turpentine extension to enable Magento and Varnish to work together and you wish to only support traffic at www.example.com and not example.com, you would need to enable the setting in the Turpentine module to normalize the host.

Apr 14, 2014
One minute

Varnish and Magento Performance Mystery

One of the things that you think you will solve when you implement a Varnish caching server in front of a Magento website is performance problems. However, this is not necessarily the case.

When I set Varnish up to cache content in front of my Magento website, I get what seems to be much improved performance. If I run a few tests in the developer tools of Chrome, it seems that the waterfall chart makes sense and the data is loaded appropriately and in a timely manner with the main HTML being downloaded in about 300ms.