Installation:
composer.json under "require":
"bmatzner/modernizr-bundle": "~2.7"
composer update bmatzner/modernizr-bundle.AppKernel.php:
new Bmatzner\ModernizrBundle\BmatznerModernizrBundle(),
php app/console assets:install web --symlink
First Use Case:
base.html.twig):
<script src="{{ asset('bundles/bmatznermodernizr/js/modernizr.min.js') }}"></script>
if (Modernizr.touch) {
// Enable touch-specific logic
}
Where to Look First:
bundles/bmatznermodernizr/js/modernizr.min.js path for the pre-built Modernizr file.Resources/public/js directory for custom builds (Foundation-compatible).Feature Detection in Templates:
{% if 'touch' in app.request.headers.get('Modernizr', '[]') %}
{{ include('touch-specific-styles.css') }}
{% endif %}
Custom Builds:
bundles/bmatznermodernizr/js/modernizr.min.js with your own build.modernizr.min.js).Integration with Asset Management:
Asset component to version Modernizr:
<script src="{{ asset('bundles/bmatznermodernizr/js/modernizr.min.js', {'version': '1.0'}) }}"></script>
Dynamic Feature Loading:
load method to dynamically inject scripts:
Modernizr.load([
{ test: Modernizr.geolocation, yep: 'geo-script' }
]);
Development Workflow:
app/Resources/BmatznerModernizrBundle/views/ (if supported).--watch with assets:install for live updates:
php app/console assets:install web --symlink --watch
Testing:
CI/CD:
assets:install runs in your CI pipeline (e.g., GitHub Actions) to validate asset paths.Bundle Deprecation:
symfony/webpack-encore for modern asset management.Asset Path Assumptions:
web/bundles/bmatznermodernizr/. If using a custom public directory (e.g., public/), update the assets:install path:
php app/console assets:install public --symlink
bundles/bmatznermodernizr/) may break if the bundle is moved.Modernizr 2.x Limitations:
classList polyfills, limited CSS feature detection).Symfony 2.x Compatibility:
AppKernel changes, asset management updates).Missing Modernizr:
ls web/bundles/bmatznermodernizr/js/modernizr.min.js
bmatznermodernizr vs. bmatzner_modernizr).Feature Detection Failures:
console.log('sessionStorage' in window)).Console Errors:
(function() {
// Modernizr code here
}).call(this);
Extend the Bundle:
Resources/public/js/modernizr.min.js by creating a custom build and placing it in:
web/bundles/bmatznermodernizr/js/custom-modernizr.min.js
Performance Optimization:
<script src="{{ asset('bundles/bmatznermodernizr/js/modernizr.min.js') }}" async></script>
Fallback for Older Browsers:
no-load to provide fallbacks:
Modernizr.load({
test: Modernizr.geolocation,
nope: 'legacy-geo-script.js'
});
Alternative for Modern Projects:
@supports rules for CSS features.window.matchMedia, Element.classList, etc.Legacy Browser Support:
addEventListener or classList alongside Modernizr. Example:
<!--[if lt IE 9]>
<script src="path/to/html5shiv.min.js"></script>
<![endif]-->
How can I help you explore Laravel packages today?