Integrate Phalcon with Medianova CDN
Learn how to integrate Phalcon, a high-performance PHP framework, with Medianova CDN to serve static assets efficiently and enhance website performance.
Phalcon is an open-source PHP framework designed for speed and efficiency. Unlike traditional PHP frameworks, Phalcon is implemented as a C extension, providing exceptional execution performance with MVC architecture support.
This guide explains multiple integration methods for connecting Phalcon-based applications with Medianova CDN to deliver static files (CSS, JS, images) from the nearest CDN edge.
Prerequisites
A configured CDN Resource
Access to the Phalcon project source code
PHP 7.4 or later (recommended)
Integration Methods
Use setStaticBaseUri
setStaticBaseUriThe simplest way to integrate your Phalcon application with Medianova CDN is by defining a static base URI. This approach ensures that dynamic content stays on your origin, while static files (CSS, JS, images) are delivered via CDN.
<?php
$url = new Phalcon\Mvc\Url();
// Dynamic URIs remain on your origin server
$url->setBaseUri('/');
// Static resources go through Medianova CDN
$url->setStaticBaseUri('https://<CDN_ZONE_URL>/');
Use Asset Collections with Conditional CDN Prefix
For more granular control, you can configure your asset collections to automatically switch between development and production environments.
<?php
$css = $this->assets->collection('header');
$scripts = $this->assets->collection('footer');
if ($config->environment == 'development') {
$css->setPrefix('/');
$scripts->setPrefix('/');
} else {
$cdnURL = 'https://<CDN_ZONE_URL>/';
$css->setPrefix($cdnURL);
$scripts->setPrefix($cdnURL);
}
$css->addCss('css/bootstrap.min.css')
->addCss('css/custom.css');
$scripts->addJs('js/jquery.js')
->addJs('js/bootstrap.min.js');
Troubleshooting
Assets are still served from the origin
The CDN prefix is not applied in code.
Verify that setStaticBaseUri() or $css->setPrefix() includes your correct CDN Resource URL.
Invalid asset paths
The CDN prefix or local directory structure is incorrect.
Check the path structure inside your assets directory and ensure the CDN path matches the file hierarchy.
SSL-related warnings
HTTPS not enabled on CDN resource.
Enable Shared SSL or Custom SSL in the Medianova Control Panel before using HTTPS URLs.
Last updated
Was this helpful?