Table of Contents
Research on CDN solutions for Magento resource issues, magento resource cdn solutions
Home Backend Development PHP Tutorial Research on CDN solutions on Magento resource issues, magento resource cdn solution_PHP tutorial

Research on CDN solutions on Magento resource issues, magento resource cdn solution_PHP tutorial

Jul 12, 2016 am 08:58 AM
cdn magento superior plan Research resource question

Research on CDN solutions for Magento resource issues, magento resource cdn solutions

Through understanding of Magento, I found that Magento’s resource files are mainly distributed in three folders: media, js, and skin. , the media folder mainly includes the system’s built-in editor WYSIWYG Editor, all the resources involved in the editor (Static Blocks, Pages, Product Intro, Product Images) and the media resources independently generated by Magento (including the media resources that we allow users to upload files folder); the skin folder is mainly the styles, pictures, and js resources provided by the template (generally, when we re-modify the template, we will change the resources in this folder); the js folder includes Magento official prototype, varien, scriptaculous, mage and other js libraries and ancillary resources (generally we will not touch this folder). All these three folders contain static resources (pictures, js, css, fonts, documents, etc.), which means we can CDN File

By observing the Magento source code, the website’s public method getBaseUrl AT app/core/Mage/Core/Model/Store.php

<span>public</span> <span>function</span> getBaseUrl(<span>$type</span> = self::URL_TYPE_LINK, <span>$secure</span> = <span>null</span><span>)
{
    </span><span>$cacheKey</span> = <span>$type</span> . '/' . (<span>is_null</span>(<span>$secure</span>) ? 'null' : (<span>$secure</span> ? 'true' : 'false'<span>));
    </span><span>if</span> (!<span>isset</span>(<span>$this</span>->_baseUrlCache[<span>$cacheKey</span><span>])) {
        </span><span>switch</span> (<span>$type</span><span>) {
            </span><span>case</span> self::URL_TYPE_WEB:
                <span>$secure</span> = <span>is_null</span>(<span>$secure</span>) ? <span>$this</span>->isCurrentlySecure() : (bool)<span>$secure</span><span>;
                </span><span>$url</span> = <span>$this</span>->getConfig('web/' . (<span>$secure</span> ? 'secure' : 'unsecure') . '/base_url'<span>);
                </span><span>break</span><span>;

            </span><span>case</span> self::URL_TYPE_LINK:
                <span>$secure</span> = (bool) <span>$secure</span><span>;
                </span><span>$url</span> = <span>$this</span>->getConfig('web/' . (<span>$secure</span> ? 'secure' : 'unsecure') . '/base_link_url'<span>);
                </span><span>$url</span> = <span>$this</span>->_updatePathUseRewrites(<span>$url</span><span>);
                </span><span>$url</span> = <span>$this</span>->_updatePathUseStoreView(<span>$url</span><span>);
                </span><span>break</span><span>;

            </span><span>case</span> self::URL_TYPE_DIRECT_LINK:
                <span>$secure</span> = (bool) <span>$secure</span><span>;
                </span><span>$url</span> = <span>$this</span>->getConfig('web/' . (<span>$secure</span> ? 'secure' : 'unsecure') . '/base_link_url'<span>);
                </span><span>$url</span> = <span>$this</span>->_updatePathUseRewrites(<span>$url</span><span>);
                </span><span>break</span><span>;

            </span><span>case</span> self::URL_TYPE_SKIN:
            <span>case</span> self::URL_TYPE_JS:
                <span>$secure</span> = <span>is_null</span>(<span>$secure</span>) ? <span>$this</span>->isCurrentlySecure() : (bool) <span>$secure</span><span>;
                </span><span>$url</span> = <span>$this</span>->getConfig('web/' . (<span>$secure</span> ? 'secure' : 'unsecure') . '/base_' . <span>$type</span> . '_url'<span>);
                </span><span>break</span><span>;

            </span><span>case</span> self::URL_TYPE_MEDIA:
                <span>$url</span> = <span>$this</span>->_updateMediaPathUseRewrites(<span>$secure</span><span>);
                </span><span>break</span><span>;

            </span><span>default</span>:
                <span>throw</span> Mage::<span>exception</span>('Mage_Core', Mage::helper('core')->__('Invalid base url type'<span>));
        }

        </span><span>if</span> (<span>false</span> !== <span>strpos</span>(<span>$url</span>, '{{base_url}}'<span>)) {
            </span><span>$baseUrl</span> = Mage::getConfig()->substDistroServerVars('{{base_url}}'<span>);
            </span><span>$url</span> = <span>str_replace</span>('{{base_url}}', <span>$baseUrl</span>, <span>$url</span><span>);
        }

        </span><span>$this</span>->_baseUrlCache[<span>$cacheKey</span>] = <span>rtrim</span>(<span>$url</span>, '/') . '/'<span>;
    }

    </span><span>return</span> <span>$this</span>->_baseUrlCache[<span>$cacheKey</span><span>];
}</span>
Copy after login

The method of obtaining URL_TYPE_MEDIA is more complicated. Let’s also take a look at what is written

<span>protected</span> <span>function</span> _updateMediaPathUseRewrites(<span>$secure</span> = <span>null</span>, <span>$type</span> = self::<span>URL_TYPE_MEDIA)
{
    </span><span>$secure</span> = <span>is_null</span>(<span>$secure</span>) ? <span>$this</span>->isCurrentlySecure() : (bool) <span>$secure</span><span>;
    </span><span>$secureStringFlag</span> = <span>$secure</span> ? 'secure' : 'unsecure'<span>;
    </span><span>$url</span> = <span>$this</span>->getConfig('web/' . <span>$secureStringFlag</span> . '/base_' . <span>$type</span> . '_url'<span>);
    </span><span>if</span> (!<span>$this</span>->getConfig(self::<span>XML_PATH_USE_REWRITES)
        </span>&& Mage::helper('core/file_storage_database')-><span>checkDbUsage()
    ) {
        </span><span>$urlStart</span> = <span>$this</span>->getConfig('web/' . <span>$secureStringFlag</span> . '/base_url'<span>);
        </span><span>$url</span> = <span>str_replace</span>(<span>$urlStart</span>, <span>$urlStart</span> . self::MEDIA_REWRITE_SCRIPT, <span>$url</span><span>);
    }
    </span><span>return</span> <span>$url</span><span>;
}</span>
Copy after login

We can find that all $type types will always be obtained from getConfig(string configPath), and the obtained saved database can be configured and modified in the background configuration -> general Web -> Unsecure & Secure.

Assume that the entire Magento site is used as a CDN source server, and then the values ​​​​of BASE_MEDIA_URL, BASE_SKIN_URL, and BASE_JS_URL are changed to CDN addresses. Does this mean that the Magento resources are CDN processed? So I first changed the local machine Install Magento for testing (as the saying goes, practice is the only way to test truth). Since CDN requires domain name resolution, we will ignore it for the time being and will not engage in CDN. However, we can use redirection to a new domain name to represent this CDN. For example, add two domain names to hosts for testing

  <span>127.0</span>.<span>0.1</span><span>       magento.yourdomain.com
  </span><span>127.0</span>.<span>0.1</span>       mage-cdn.yourdomain.com
Copy after login

Copy the original magento.yourdomain.com configuration in Nginx and delete the PHP parsing section to ensure safety. By the way, add as many resource types as possible to the resources (you can add more later if not enough)

Restart nginx, then log in to the Magento backend and change the original {{base_unsecure_url}} in BASE_MEDIA_URL, BASE_SKIN_URL, and BASE_JS_URL to http://mage-cdn.yourdomain.com/ and {{base_secure_url}} to https: //mage-cdn.yourdomain.com/ Then save the settings and refresh the Magento cache. OK. You're done.

Open http://magento.yourdomain.com/ and try it. Suppose you use another template and add a lot of fonts to it. You may see an error message about cross-domain access:

Font from origin <span>'</span><span>https://mage-cdn.yourdomain.com</span><span>'</span> has been blocked from loading by Cross-Origin Resource Sharing policy: No <span>'</span><span>Access-Control-Allow-Origin</span><span>'</span> header is present on the requested resource. Origin <span>'</span><span>https://magento.yourdomain.com</span><span>'</span> is therefore <span>not</span> allowed access.
Copy after login

He told you that the magento site wants to access some resources of mage-cdn, but since there is no Access-Control-Allow-Origin header, we add add_header Access-Control when configuring the resource files in the mage-cdn site in nginx. -Allow-Origin https://magento.yourdomain.com. Why not use *? If you generously want other websites to be able to access your resources across domains, then you can use *. I recommend using binding there. Where, hehe

Then we open the Magento site, conduct various tests, register, log in, place an order, upload and edit various things in the background. OK, this time we are really done.

The next step is to deploy the CDN. Log in to the CDN service provider and directly set the source site to your magento.yourdomain.com. Generally, CDNs provide CNAME services, so you can generously parse a cdn.yourdomain.com CNAME to provide CDN services. The address abcd.xxxx.com provided to you by the provider. Generally, CDN service providers also provide the addition of headers. You can add the required headers for this CDN, which is the cross-domain request we need. Then configure Magento and then blablabla. Finally, you find a way to let the CDN service provider use your crt certificate. OK It’s done now

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1102846.htmlTechArticleResearch on CDN solution for Magento resource issues, magento resource cdn solution Through understanding of Magento, I found that Magento’s resource files are mainly Distributed in three folders: media, js, skin, media files...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

A deep dive into models, data, and frameworks: an exhaustive 54-page review of efficient large language models A deep dive into models, data, and frameworks: an exhaustive 54-page review of efficient large language models Jan 14, 2024 pm 07:48 PM

Large-scale language models (LLMs) have demonstrated compelling capabilities in many important tasks, including natural language understanding, language generation, and complex reasoning, and have had a profound impact on society. However, these outstanding capabilities require significant training resources (shown in the left image) and long inference times (shown in the right image). Therefore, researchers need to develop effective technical means to solve their efficiency problems. In addition, as can be seen from the right side of the figure, some efficient LLMs (LanguageModels) such as Mistral-7B have been successfully used in the design and deployment of LLMs. These efficient LLMs can significantly reduce inference memory while maintaining similar accuracy to LLaMA1-33B

Digital audio output interface on the motherboard-SPDIF OUT Digital audio output interface on the motherboard-SPDIF OUT Jan 14, 2024 pm 04:42 PM

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

How to find resources on 115 network disk How to find resources on 115 network disk Feb 23, 2024 pm 05:10 PM

There will be a lot of resources in the 115 network disk, so how to find resources? Users can search for the resources they need in the software, then enter the download interface, and then choose to save to the network disk. This introduction to the method of finding resources on 115 network disk can tell you the specific content. The following is a detailed introduction, come and take a look. How to find resources on 115 network disk? Answer: Search the content in the software, and then click to save to the network disk. Detailed introduction: 1. First enter the resources you want in the app. 2. Then click the keyword link that appears. 3. Then enter the download interface. 4. Click Save to network disk inside.

Clustering effect evaluation problem in clustering algorithm Clustering effect evaluation problem in clustering algorithm Oct 10, 2023 pm 01:12 PM

The clustering effect evaluation problem in the clustering algorithm requires specific code examples. Clustering is an unsupervised learning method that groups similar samples into one category by clustering data. In clustering algorithms, how to evaluate the effect of clustering is an important issue. This article will introduce several commonly used clustering effect evaluation indicators and give corresponding code examples. 1. Clustering effect evaluation index Silhouette Coefficient Silhouette coefficient evaluates the clustering effect by calculating the closeness of the sample and the degree of separation from other clusters.

Why did Han Xiaoquan suddenly have no resources? Why did Han Xiaoquan suddenly have no resources? Feb 24, 2024 pm 03:22 PM

Han Xiaoquan is a software that can watch many Korean dramas, so why is there suddenly no resource? This software may have no resources due to network problems, version problems, or copyright issues. This article about the reason why Han Xiaoquan suddenly has no resources can tell you the specific content. The following is a detailed introduction, come and take a look. Why did Han Xiaoquan suddenly have no resources? Answer: Due to network problems, version problems, and copyright issues, detailed introduction: 1. Solution to network problems: You can choose a different network, and then log in to the software again to try. 2. Solution to version problems: Users can download the latest version of this software from the official website. 3. Solutions to copyright issues: Some Korean dramas are removed from the shelves due to copyright issues. You can choose other Korean dramas to watch.

Teach you how to diagnose common iPhone problems Teach you how to diagnose common iPhone problems Dec 03, 2023 am 08:15 AM

Known for its powerful performance and versatile features, the iPhone is not immune to the occasional hiccup or technical difficulty, a common trait among complex electronic devices. Experiencing iPhone problems can be frustrating, but usually no alarm is needed. In this comprehensive guide, we aim to demystify some of the most commonly encountered challenges associated with iPhone usage. Our step-by-step approach is designed to help you resolve these common issues, providing practical solutions and troubleshooting tips to get your equipment back in peak working order. Whether you're facing a glitch or a more complex problem, this article can help you resolve them effectively. General Troubleshooting Tips Before delving into specific troubleshooting steps, here are some helpful

VPR 2024 perfect score paper! Meta proposes EfficientSAM: quickly split everything! VPR 2024 perfect score paper! Meta proposes EfficientSAM: quickly split everything! Mar 02, 2024 am 10:10 AM

This work of EfficientSAM was included in CVPR2024 with a perfect score of 5/5/5! The author shared the result on a social media, as shown in the picture below: The LeCun Turing Award winner also strongly recommended this work! In recent research, Meta researchers have proposed a new improved method, namely mask image pre-training (SAMI) using SAM. This method combines MAE pre-training technology and SAM models to achieve high-quality pre-trained ViT encoders. Through SAMI, researchers try to improve the performance and efficiency of the model and provide better solutions for vision tasks. The proposal of this method brings new ideas and opportunities to further explore and develop the fields of computer vision and deep learning. by combining different

I2V-Adapter from the SD community: no configuration required, plug and play, perfectly compatible with Tusheng video plug-in I2V-Adapter from the SD community: no configuration required, plug and play, perfectly compatible with Tusheng video plug-in Jan 15, 2024 pm 07:48 PM

The image-to-video generation (I2V) task is a challenge in the field of computer vision that aims to convert static images into dynamic videos. The difficulty of this task is to extract and generate dynamic information in the temporal dimension from a single image while maintaining the authenticity and visual coherence of the image content. Existing I2V methods often require complex model architectures and large amounts of training data to achieve this goal. Recently, a new research result "I2V-Adapter: AGeneralImage-to-VideoAdapter for VideoDiffusionModels" led by Kuaishou was released. This research introduces an innovative image-to-video conversion method and proposes a lightweight adapter module, i.e.

See all articles