You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `cdn_url` function accepts an optional second argument to specify the URL reference type. See Symfony's [UrlGeneratorInterface](https://symfony.com/doc/current/routing.html#generating-urls) for available options (`ABSOLUTE_URL`, `ABSOLUTE_PATH`, `RELATIVE_PATH`, `NETWORK_PATH`).
704
+
705
+
#### Supported Formats
706
+
707
+
The CDN supports all file formats served by Storyblok, including images (JPG, PNG, WebP, GIF, SVG, AVIF), documents (PDF), and other assets.
708
+
709
+
**Example URLs:**
710
+
711
+
| Asset Type | Storyblok URL | CDN URL |
712
+
|------------|---------------|---------|
713
+
| Original image | `https://a.storyblok.com/f/12345/1920x1080/abc123/photo.jpg` | `https://example.com/f/a1b2c3d4e5f6g7h8/1920x1080-photo.jpg` |
The CDN feature uses a lazy-loading approach for optimal performance:
744
+
745
+
1. **During Twig rendering**: When `cdn_url()` is called, only metadata (the original Storyblok URL) is stored locally. No download occurs at this point, keeping page rendering fast.
746
+
747
+
2. **On first browser request**: When a browser requests the CDN URL, the controller downloads the file from Storyblok, stores it locally with enriched metadata (content type, etag, expiration), and serves it.
748
+
749
+
3. **On subsequent requests**: The file is served directly from local storage with appropriate caching headers.
750
+
751
+
This approach ensures that page rendering is not blocked by asset downloads, even when dealing with many images.
752
+
753
+
### Custom Storage Implementation
754
+
755
+
By default, assets are stored on the filesystem. You can implement your own storage by creating a class that implements `CdnStorageInterface`:
756
+
757
+
```php
758
+
use Storyblok\Bundle\Cdn\Storage\CdnStorageInterface;
759
+
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
760
+
761
+
#[AsAlias(CdnStorageInterface::class)]
762
+
final class RedisCdnStorage implements CdnStorageInterface
763
+
{
764
+
// Implement the interface methods
765
+
}
766
+
```
767
+
768
+
Then configure the bundle to use custom storage:
769
+
770
+
```yaml
771
+
# config/packages/storyblok.yaml
772
+
storyblok:
773
+
cdn:
774
+
storage:
775
+
type: custom # This removes the built-in filesystem storage
776
+
```
777
+
778
+
> [!NOTE]
779
+
> When using `type: custom`, the `path` option should not be set. The built-in cleanup command is also removed since it's specific to filesystem storage.
780
+
629
781
### Image Transformation
630
782
631
783
The bundle provides a `storyblok_image` Twig filter to convert Storyblok Assets to Image objects with optional resizing. This filter integrates with the [storyblok/php-image-service](https://github.com/storyblok/php-image-service) library and returns an immutable `Image` instance that you can further transform using the fluent API.
0 commit comments