2. @kriswallsmith
• Symfony Guru at
• Symfony core team member
• Doctrine contributor
• 10+ years experience with PHP and web development
• Open source evangelist and international speaker
3. OpenSky connects you with innovators,
trendsetters and tastemakers.You choose
the ones you like and each week they
invite you to their private online sales.
4. OpenSky connects you with innovators,
trendsetters and tastemakers.You choose
the ones you like and each week they
invite you to their private online sales.
21. as•cet•i•cism
describes a lifestyle characterized by abstinence from various sorts of worldly
pleasures often with the aim of pursuing religious and spiritual goals
25. # /path/to/web/js/core.php
$core = new AssetCollection(array(
new FileAsset('/path/to/jquery.js'),
new GlobAsset('/path/to/js/core/*.js'),
));
$core->load();
header('Content-Type: text/javascript');
echo $core->dump();
26. # /path/to/web/js/core.php
$core = new AssetCollection(array(
new FileAsset('/path/to/jquery.js'),
new GlobAsset('/path/to/js/core/*.js'),
));
$core->load();many files into one == fewer HTTP requests
Merge
header('Content-Type: text/javascript');
echo $core->dump();
27. # /path/to/web/js/core.php
$core = new AssetCollection(array(
new FileAsset('/path/to/jquery.js'),
new GlobAsset('/path/to/js/core/*.js'),
), array(
new YuiCompressorJsFilter('/path/to/yui.jar'),
));
$core->load();
header('Content-Type: text/javascript');
echo $core->dump();
28. # /path/to/web/js/core.php
$core = new AssetCollection(array(
new FileAsset('/path/to/jquery.js'),
new GlobAsset('/path/to/js/core/*.js'),
), array(
new YuiCompressorJsFilter('/path/to/yui.jar'),
));
$core->load();
Compress the merged asset == less data over the wire
header('Content-Type: text/javascript');
echo $core->dump();
45. # /path/to/web/css/styles.php
$styles = new FileAsset('/path/to/main.sass', array(
new SassFilter(),
));
header('Content-Type: text/css');
echo $styles->dump();
46. # /path/to/web/css/styles.php
$styles = new FileAsset('/path/to/main.sass', array(
new SassFilter(),
));
Load is implied
header('Content-Type: text/css');
echo $styles->dump();
47. # /path/to/web/css/styles.php
$styles = new AssetCollection(array(
new FileAsset('/path/to/main.sass', array(
new SassFilter(),
)),
new FileAsset('/path/to/more.css'),
));
header('Content-Type: text/css');
echo $styles->dump();
48. # /path/to/web/css/styles.php
$styles = new AssetCollection(array(
new FileAsset('/path/to/main.sass', array(
new SassFilter(),
)),
new FileAsset('/path/to/more.css'),
), array(
new YuiCompressorCss('/path/to/yui.jar'),
));
header('Content-Type: text/css');
echo $styles->dump();
49. # /path/to/web/css/styles.php
$styles = new AssetCollection(array(
new FileAsset('/path/to/main.sass', array(
new SassFilter(),
)),
new FileAsset('/path/to/more.css'),
), array(
new YuiCompressorCss('/path/to/yui.jar'),
));
Lazy! The filesystem isn't touched until now
header('Content-Type: text/css');
echo $styles->dump();
56. jQuery will only be included once
$core = new AssetCollection(array(
$jquery,
$plugin1,
$plugin2,
));
header('text/javascript');
echo $core->dump();
58. $yui = new YuiCompressorJs();
$yui->setNomunge(true);
$fm = new FilterManager();
$fm->set('yui_js', $yui);
59. $jquery = new FileAsset('/path/to/core.js');
$jquery->ensureFilter($fm->get('yui_js'));
$core = new AssetCollection(array(
$jquery,
new GlobAsset('/path/to/js/core/*.js'),
));
$core->ensureFilter($fm->get('yui_js'));
60. jQuery will only be compressed once
$jquery = new FileAsset('/path/to/core.js');
$jquery->ensureFilter($fm->get('yui_js'));
$core = new AssetCollection(array(
$jquery,
new GlobAsset('/path/to/js/core/*.js'),
));
$core->ensureFilter($fm->get('yui_js'));
62. $fm = new FilterManager();
$fm->set('coffee', new CoffeeScriptFilter());
$fm->set('closure', new ClosureFilter());
$factory = new AssetFactory('/path/to/web');
$factory->setFilterManager($fm);
72. # /path/to/web/css/styles.php
$styles = new AssetCache(new AssetCollection(
array(new FileAsset('/path/to/main.sass')),
array(new SassFilter())
), new FilesystemCache('/path/to/cache'));
echo $styles->dump();
73. # /path/to/web/css/styles.php
$styles = new AssetCache(new AssetCollection(
array(new FileAsset('/path/to/main.sass')),
array(new SassFilter())
), new FilesystemCache('/path/to/cache'));
Run the filters once and cache the content
echo $styles->dump();
94. $loader = new FunctionCallsFormulaLoader();
$resource = new DirectoryResource(
'/path/to/templates',
'/.php$/'
);
$formulae = $loader->load($resource);
95. $am = new LazyAssetManager($factory);
$am->setLoader('php', $loader);
$am->addResource($resource, 'php');
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
96. $am = new LazyAssetManager($factory);
$am->setLoader('php', $loader);
$am->addResource($resource, 'php');
Expensive every time
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
97. $cache = new ConfigCache('/path/to/cache');
$loader = new CachedFormulaLoader(
$loader,
$cache,
$debug
);
98. $cache = new ConfigCache('/path/to/cache');
$loader = new CachedFormulaLoader(
$loader,
$cache,
$debug
);
Whether to stat each file for changes