1. Go to this page and download the library: Download tomkirsch/assets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomkirsch / assets example snippets
namespace App\Controllers;
use CodeIgniter\Controller;
class MyController extends Controller{
protected $assets;
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger){
parent::initController($request, $response, $logger);
// generate assets for non-ajax requests
if(!$this->request->isAJAX()){
$this->assets = Services::assets();
// fonts
$assets->addFont([
'path' => 'anton',
'family' => 'Anton',
'name' => 'anton',
'weight' => '400',
'style' => 'normal',
'priority' => 'pre_dom',
'type' => 'css',
'fallbacks' => 'woff2,woff,ttf,eot',
]);
// styles
$assets->addStyles([
[
'content'=>'css/main.css',
'priority'=>$this->assets::PRIORITY_POSTDOM_LOCAL,
],
]);
// scripts
$assets->addScripts([
'main.js', // strings are assumed post-dom local priority
]);
}
}
public function mymethod(){
// styles
$this->assets->addStyles([
[
'content'=>'css/critical.css',
'critical'=>TRUE,
],
[
'content'=>'css/one.css',
'priority'=>$this->assets::PRIORITY_POSTDOM_LOCAL,
],
[
'content'=>'css/two.css',
'priority'=>$this->assets::PRIORITY_POSTDOM_LOCAL,
],
]);
// scripts
$this->assets->addScripts([
[
'content'=>'test-one.js',
'priority'=>$this->assets::PRIORITY_PREDOM_LOCAL,
],
// post-DOM local scripts can just be string file names
'test-two.js',
'test-three.js',
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.