SlideShare a Scribd company logo
1 of 114
Download to read offline
assetic
@kriswallsmith
things are pretty good
things could be better
problems
solutions
past
present
future
kriswallsmith/assetic
inspired by python’s webassets
http://github.com/miracle2k/webassets
2,500+ stars
400+ forks
2.4 million installs
the team
• kriswallsmith
• stof
• schmittjoh
• everzet
• 88 other contributors
boring
css
javascript
such assets
so wait
wow
model the problem
assets
images stylesheets javascripts
• path
• last modified
• content
an object-oriented api
interface AssetInterface!
{!
function getContent();!
function getSourceRoot();!
function getSourcePath();!
function getTargetPath();!
function getLastModified();!
!
// ...!
}
interface AssetInterface!
{!
// ...!
!
function load();!
function dump();!
!
// ...!
}
implementations
• StringAsset
• FileAsset
• HttpAsset
use AsseticAssetStringAsset;!
!
$a = new StringAsset('alert("hi!")');!
$a->load();!
echo $a->dump();
use AsseticAssetStringAsset;!
!
$a = new StringAsset('alert("hi!")');!
$a->load();!
echo $a->dump();
use AsseticAssetStringAsset;!
!
$a = new StringAsset('alert("hi!")');!
!
echo $a->dump();
use AsseticAssetFileAsset;!
!
$a = new FileAsset('/path/to/hi.js');!
!
echo $a->dump();
use AsseticAssetHttpAsset;!
!
$a = new HttpAsset('//example.com/hi.js');!
!
echo $a->dump();
special implementations
• AssetCollection
• GlobAsset
• AssetCache
• AssetReference
use AsseticAssetAssetCollection;!
use AsseticAssetFileAsset;!
use AsseticAssetStringAsset;!
!
$a = new AssetCollection(array(!
new StringAsset('// (c) me'),!
new FileAsset('/path/to/main.js'),!
));!
!
echo $a->dump();
use AsseticAssetGlobAsset;!
!
$a = new GlobAsset('/path/to/js/*.js');!
!
echo $a->dump();
use AsseticAssetAssetCache;!
use AsseticAssetHttpAsset;!
use AsseticCacheApcCache;!
!
$a = new AssetCache(!
new HttpAsset(‘//example.com/hi.js'),!
new ApcCache()!
);!
!
echo $a->dump();
use AsseticAssetAssetReference;!
use AsseticAssetStringAsset;!
use AsseticAssetManager;!
!
$am = new AssetManager();!
$am->set('hi', new StringAsset('...'));!
!
$a = new AssetReference($am, 'hi');!
!
echo $a->dump();
slow
fewer requests
smaller responses
tools
• CssEmbed
• Google Closure
• jpegoptim
• jpegtran
• JSMin
• JSqueeze

• optipng
• PhpCssEmbed
• pngout
• UglifyCSS
• UglifyJS
• YUI Compressor
tedious
more tools
• CoffeeScript
• Compass
• Dart
• Less
• Lessphp
• Packager

• Roole
• SASS
• Scssphp
• Sprockets
• Stylus
• TypeScript
model the problem
use AsseticAssetAssetInterface as Asset;!
!
interface FilterInterface!
{!
function filterLoad(Asset $asset);!
function filterDump(Asset $asset);!
}
var myVariable var _a
dumpload
coffeescript javascript
load javascript
• CoffeeScriptFilter
• DartFilter
• EmberPrecompileFilter
• HandlebarsFilter

• PackagerFilter
• SprocketsFilter
• TypeScriptFilter
load css
• CompassFilter
• CssImportFilter
• GssFilter
• LessFilter
• LessphpFilter
• PhpCssEmbedFilter
• RooleFilter
• SassSassFilter
• SassScssFilter
• ScssphpFilter
• StylusFilter
dump javascript
• GoogleCompilerApiFilter
• GoogleCompilerJarFilter
• JSMinFilter
• JSMinPlusFilter
• JSqueezeFilter

• PackerFilter
• UglifyJsFilter
• UglifyJs2Filter
• YuiJsCompressorFilter
dump css
• CssEmbedFilter
• CssMinFilter
• CssRewriteFilter
• UglifyCssFilter
• YuiCssCompressorFilter
dump images
• JpegoptimFilter
• JpegtranFilter
• OptiPngFilter
• PngoutFilter
use AsseticFilterFilterInterface;!
!
interface AssetInterface!
{!
function ensureFilter(!
FilterInterface $filter);!
!
// ...!
}
use AsseticAssetFileAsset;!
use AsseticFilterCoffeeScriptFilter;!
use AsseticFilterUglifyJs2Filter;!
!
$a = new FileAsset('/path/to/app.coffee');!
$a->ensureFilter(new CoffeeScriptFilter());!
$a->ensureFilter(new UglifyJs2Filter());!
!
echo $a->dump();
use AsseticAssetFileAsset;!
use AsseticFilterCoffeeScriptFilter;!
use AsseticFilterUglifyJs2Filter;!
!
$a = new FileAsset(!
'/path/to/app.coffee',!
array(!
new CoffeeScriptFilter(),!
new UglifyJs2Filter(),!
)!
);
serve
# /path/to/web/js/app.php!
!
$a = new FileAsset('/path/to/app.coffee');!
$a->ensureFilter(new CoffeeScriptFilter());!
$a->ensureFilter(new UglifyJs2Filter());!
!
header('Content-Type: text/javascript');!
echo $a->dump();
# /path/to/web/js/app.php!
!
use AsseticAssetAssetCache;!
use AsseticCacheApcCache;!
!
// ...!
!
$a = new AssetCache($a, new ApcCache());!
!
header('Content-Type: text/javascript');!
echo $a->dump();
flat
use AsseticAssetFileAsset;!
use AsseticAssetManager;!
use AsseticAssetWriter;!
!
$a = new FileAsset('/path/to/app.js');!
$a->setTargetPath('js/app.js');!
!
$am = new AssetManager();!
$am->set('app_js', $a);!
!
$writer = new AssetWriter('/path/to/web');!
$writer->writeManagerAssets($am);
reference
<script src="/js/app.php"></script>
<script src="/js/app.js"></script>
<script src="<?= asset('app_js') ?>"></scri
template as configuration
<script src="<?=!
assetic_javascripts(!
array('js/app.coffee'),!
array('coffee', 'uglifyjs2'),!
array('output' => 'js/app.js')!
)!
?>"></script>
use AsseticFilterCoffeeScriptFilter;!
use AsseticFilterManager;!
!
$fm = new FilterManager();!
$fm->set(!
'coffee',!
new CoffeeScriptFilter()!
);
use AsseticFactoryAssetFactory;!
!
$factory = new AssetFactory('/www');!
$factory->setFilterManager($fm);
use ...LoaderFunctionCallsFormulaLoader;!
use ...ResourceDirectoryResource;!
!
$ldr = new FunctionCallsFormulaLoader();!
$rsc = new DirectoryResource(!
'/path/to/views',!
'/.php$/'!
);
use AsseticFactoryLazyAssetManager;!
!
$am = new LazyAssetManager($factory);!
$am->setLoader('php', $ldr);!
$am->addResource($rsc, 'php');
detect
includes
references
while (true) {!
foreach ($am->getNames() as $name) {!
// ...!
}!
!
sleep(1);!
}
push
henrikbjorn/lurker
use LurkerResourceWatcher;!
!
$watcher = new ResourceWatcher();!
$watcher->track('twig', '/path/to/views');!
$watcher->addListener('twig', function($e) {!
// ...!
});!
!
$watcher->start();
respond
_colors.sass
foreach ($am->getNames() as $name) {!
$asset = $am->get($name);!
// ...!
!
if ($match) {!
// ...!
}!
}
graph
profile.sass
_colors.sass background.gif
home.sass
includes
includes
references
references
included by
included by
referenced by
referenced by
nodes
edges
profile.sass
_colors.sass background.gif
home.sass
includes
includes
references
references
included by
included by
referenced by
referenced by
profile.sass
_colors.sass background.gif
home.sass
includes
includes
references
references
included by
included by
referenced by
referenced by
profile.sass
_colors.sass background.gif
home.sass
includes
includes
references
references
included by
included by
referenced by
referenced by
use AsseticAssetHttpAsset;!
!
$a = new HttpAsset('//example.com/hi.js');
• proxy
• authentication
• errors
• ssl
• mock

• test

• logging
• profiling
• curl
• guzzle
represent
separate
• load
• filter
• reflection
• optimization
maintain
~40 filters
ping
opinion
• engines
• javascript optimizer
• css optimizer
• jpeg optimizer
• png optimizer
sponsor
follow
@kriswallsmith
hire
• workshops
• architecture
• audits
• performance

• symfony
• phpunit
• twig
• doctrine
questions?
kris.wallsmith@gmail.com

More Related Content

What's hot

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
dmethvin
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
girish82
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
brinsknaps
 

What's hot (20)

Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
 
jQuery
jQueryjQuery
jQuery
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
Jquery Best Practices
Jquery Best PracticesJquery Best Practices
Jquery Best Practices
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Jquery
JqueryJquery
Jquery
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 

Similar to Drupal, meet Assetic

Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
takezoe
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
Shawn Meng
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Objective C 基本介紹
Objective C 基本介紹Objective C 基本介紹
Objective C 基本介紹
Giga Cheng
 

Similar to Drupal, meet Assetic (20)

Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Sprockets
SprocketsSprockets
Sprockets
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
AtlasCamp 2014: Static Connect Add-ons
AtlasCamp 2014: Static Connect Add-onsAtlasCamp 2014: Static Connect Add-ons
AtlasCamp 2014: Static Connect Add-ons
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An Introduction
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Objective C 基本介紹
Objective C 基本介紹Objective C 基本介紹
Objective C 基本介紹
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 

More from Kris Wallsmith

More from Kris Wallsmith (6)

The View From Inside
The View From InsideThe View From Inside
The View From Inside
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
A Practical Introduction to Symfony2
A Practical Introduction to Symfony2A Practical Introduction to Symfony2
A Practical Introduction to Symfony2
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Symfony in the Cloud
Symfony in the CloudSymfony in the Cloud
Symfony in the Cloud
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Drupal, meet Assetic