Download the PHP package adriansuter/twig-cache-busting without Composer

On this page you can find all versions of the php package adriansuter/twig-cache-busting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig-cache-busting

Twig-Cache-Busting

Build Status Coverage Status Total Downloads License

Twig Cache Busting is an add-on for Twig to support cache busting on template compilation.

Installation

Description

This add-on would extend Twig by a cache busting mechanism. The cache busting is taking place upon compilation of the template (not upon rendering). So whenever you update an asset, you would need to recompile the templates that reference this asset (or clear the cache and let Twig rebuild it automatically). The benefit is, that if you cache your compiled templates, then the server would process the performance intense cache busting only once (not on every request).

Cache Busters

By default, there are three cache busting methods. But you can develop your own custom cache buster by implementing the \AdrianSuter\TwigCacheBusting\Interfaces\CacheBusterInterface.

Hash Generators

The Query Param Cache Buster and the File Name Cache Buster both use a hash generator to generate a hash for the given asset (in the examples above, the hash is abcd). By default the following hash generators are possible. But you can develop your own custom hash generator by implementing \AdrianSuter\TwigCacheBusting\Interfaces\HashGeneratorInterface.

Usage

Query Param Cache Buster

Assume you have a file /home/htdocs/public/assets/image.jpg and your template is as follows:

To use the Query Param Cache Buster you need to pass the QueryParamCacheBuster to the static create method of the CacheBustingTwigExtension.

By default, the QueryParamCacheBuster uses the FileModificationTimeHashGenerator. But you can set another generator by passing a second argument to the constructor. For example:

File Name Cache Buster

Assume you have a file /home/htdocs/public/assets/image.jpg and your template is as follows:

To use the File Name Cache Buster you need to pass the FileNameCacheBuster to the static create method of the CacheBustingTwigExtension.

Your web server needs to be configured such that the cache busting requests get redirected. For Apache you would need to set

Note that you might want to add more extensions to the rewrite rule.

By default, the FileNameCacheBuster uses the FileModificationTimeHashGenerator. But you can set another generator by passing a second argument to the constructor. For example:

If your hash generator returns hexadecimal hashes, then you would need to adapt the Apache rewrite rule appropriately. For example:

Dictionary Cache Buster

This cache busting method would use a dictionary to lookup file names. The dictionary is basically a mapping between the original file path and the cache busting version.

Base Path

If you want to prepend a base path to the generated paths, then simply pass that to the static create method of the CacheBustingTwigExtension. For example:

Custom Twig Tag

If you want to change the twig tag cache_busting into something else, you can do that simply by setting the third argument of the static create method of the CacheBustingTwigExtension. For example:

Now you can use cb in your templates in order to apply cache busting.

Contribution

Is much welcomed.


All versions of twig-cache-busting with dependencies

PHP Build Version
Package Version
Requires php Version ^8
twig/twig Version ^3.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package adriansuter/twig-cache-busting contains the following files

Loading the files please wait ....