Before you take any steps please back up your files and database.
This documentation guides you through the integration of CDN with the high performance PHP framework Phalcon. There are different approaches to integrate CDN, either use the base URI option, the asset management, or simply a view helper which can produce all CDN URLs for your assets.
1. Create a pull zone before you start the Phalcon CDN integration.
2. The simplest but most generic approach is to define the setStaticBaseUri
.
<?php $url = new Phalcon\Mvc\Url(); // Dynamic URIs remain on your origin server $url->setBaseUri('/'); // Static resources go through CDN $url->setStaticBaseUri('http://cdn.example.com/');
Type in your CDN Domain ot the CNAME that you specified in the SkyparkCDN control panel. Ensure that your CNAME record has been configured in a proper way befor using it for integration.
3. Alternative: Use collections and add a URL-prefix for your CDN URL.
<?php $css = $this->assets->collection('header'); $scripts = $this->assets->collection('footer'); if ($config->environment == 'development') { $css->setPrefix('/'); $scripts->setPrefix('/'); } else { $cdnURL = 'http://cdn.example.com/'; $css->setPrefix($cdnURL); $scripts->setPrefix($cdnURL); } $css->addCss('css/bootstrap.min.css') ->addCss('js/custom.css'); $scripts->addJs('js/jquery.js') ->addJs('js/bootstrap.min.js');
4. Alternative: In case you don’t want to use collections, use this approach:
... $cdnURL = 'http://cdn.example.com/'; $this->assets ->addCss($cdnURL.'css/custom.css', false); ...
Integration has been completed! We highly recommend you to check the HTML code of your webpage to ensure that URLs have been rewritten properly from your original ones to CNAME from the control panel.
To do that press F12 or open Developers Tools in your browser, choose the Network tab and refresh the page. All static files should have your CNAME in URLs.