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.

Before integration, back up your project files and database.

Prerequisites

  • A configured CDN Resource

  • Access to the Phalcon project source code

  • PHP 7.4 or later (recommended)

Integration Methods

1

Use setStaticBaseUri

The 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>/');

Replace <CDN_Resource_URL> with your actual CDN Resource URL (for example: https://example.mncdn.com/).

2

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');

This method allows you to automatically use local assets in development and CDN-prefixed URLs in production.

3

Direct CDN Path in Asset Definition

You can also directly define CDN-prefixed URLs when adding assets to your project.

<?php
$cdnURL = 'https://<CDN_ZONE_URL>/';
$this->assets
     ->addCss($cdnURL . 'css/custom.css', false);
4

Verify CDN Integration

After applying one of the methods above:

  1. Deploy your changes to the web server.

  2. Open your website in a browser.

  3. View the HTML source (Ctrl + U) and confirm that static file URLs begin with your CDN Resource domain.

Example: https://example.mncdn.com/css/bootstrap.min.css

Troubleshooting

Problem
Cause
Solution

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?