Chapters
57 Chapters
|
6:19:46
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
14.
Reloading When JS/CSS Changes
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.13.1
"doctrine/doctrine-bundle": "^2.2", // 2.3.2
"doctrine/orm": "^2.8", // 2.9.1
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^6.1", // v6.1.4
"symfony/asset": "5.3.*", // v5.3.0-RC1
"symfony/console": "5.3.*", // v5.3.0-RC1
"symfony/dotenv": "5.3.*", // v5.3.0-RC1
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.3.*", // v5.3.0-RC1
"symfony/framework-bundle": "5.3.*", // v5.3.0-RC1
"symfony/property-access": "5.3.*", // v5.3.0-RC1
"symfony/property-info": "5.3.*", // v5.3.0-RC1
"symfony/proxy-manager-bridge": "5.3.*", // v5.3.0-RC1
"symfony/runtime": "5.3.*", // v5.3.0-RC1
"symfony/security-bundle": "5.3.*", // v5.3.0-RC1
"symfony/serializer": "5.3.*", // v5.3.0-RC1
"symfony/twig-bundle": "5.3.*", // v5.3.0-RC1
"symfony/ux-chartjs": "^1.1", // v1.3.0
"symfony/ux-turbo": "^1.3", // v1.3.0
"symfony/ux-turbo-mercure": "^1.3", // v1.3.0
"symfony/validator": "5.3.*", // v5.3.0-RC1
"symfony/webpack-encore-bundle": "^1.9", // v1.11.2
"symfony/yaml": "5.3.*", // v5.3.0-RC1
"twig/extra-bundle": "^2.12|^3.0", // v3.3.1
"twig/intl-extra": "^3.2", // v3.3.0
"twig/string-extra": "^3.3", // v3.3.1
"twig/twig": "^2.12|^3.0" // v3.3.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.0
"symfony/debug-bundle": "^5.2", // v5.3.0-RC1
"symfony/maker-bundle": "^1.27", // v1.31.1
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/stopwatch": "^5.2", // v5.3.0-RC1
"symfony/var-dumper": "^5.2", // v5.3.0-RC1
"symfony/web-profiler-bundle": "^5.2", // v5.3.0-RC1
"zenstruck/foundry": "^1.10" // v1.10.0
}
}
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@babel/preset-react": "^7.0.0", // 7.13.13
"@fortawesome/fontawesome-free": "^5.15.3", // 5.15.3
"@hotwired/turbo": "^7.0.0-beta.5", // 1.2.6
"@popperjs/core": "^2.9.1", // 2.9.2
"@symfony/stimulus-bridge": "^2.0.0", // 2.1.0
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", // 1.1.0
"@symfony/ux-turbo": "file:vendor/symfony/ux-turbo/Resources/assets", // 0.1.0
"@symfony/ux-turbo-mercure": "file:vendor/symfony/ux-turbo-mercure/Resources/assets", // 0.1.0
"@symfony/webpack-encore": "^1.0.0", // 1.3.0
"bootstrap": "^5.0.0-beta2", // 5.0.1
"chart.js": "^2.9.4",
"core-js": "^3.0.0", // 3.13.0
"jquery": "^3.6.0", // 3.6.0
"react": "^17.0.1", // 17.0.2
"react-dom": "^17.0.1", // 17.0.2
"regenerator-runtime": "^0.13.2", // 0.13.7
"stimulus": "^2.0.0", // 2.0.0
"stimulus-autocomplete": "https://github.com/weaverryan/stimulus-autocomplete#toggle-event-always-dist", // 2.0.0
"stimulus-use": "^0.24.0-1", // 0.24.0-2
"sweetalert2": "^11.0.8", // 11.0.12
"webpack-bundle-analyzer": "^4.4.0", // 4.4.2
"webpack-notifier": "^1.6.0" // 1.13.0
}
}
10 Comments
In turbo 8 we also have "dynamic" for CSS, see https://github.com/hotwired/turbo/pull/1140
Hey Infourok,
That's cool, thanks for this tip! :)
Cheers!
Hey guys,
Does this mean you can't have multiple entries in your <b>webpack.config.js</b> file, combined with adding extra javascript and link tags per page when this is on? E.g.
If you do, and you visit another page, it will have new js/css, so it will always reload, right?
This is no problem if you're using all stimulus for javascript, but does this mean you would put all of your css into the main app.(s)css? Any tips for separation? I'm thinking of splitting things into partials and import them all in app.(s)css.
Thanks!
This does seem to be the case: https://discuss.hotwired.de...
Hey Vafilor!
Yes, as you already saw, this IS the case. The "reloading" system is kind of "dumb": if there are ANY new script/link tags then... boom! You get the full page reload.
Generally-speaking, I've been moving away from using multiple Webpack entry files. Instead, I'm using "dynamic imports" https://symfonycasts.com/sc... or the super-cool "lazy controllers" - https://symfonycasts.com/sc...
For me, this keeps my code simpler, but I still have the benefits of splitting things into smaller pieces to prevent having a GIANT app.js or app.css file. CSS can be dynamically imported in this exact same way.
> but does this mean you would put all of your css into the main app.(s)css?
I would put all of my "main" and most important CSS (for my general layout, etc) into this file (see note below). If I have some CSS that I'd like to not include in the final build app.css file for performance reasons, then I would try to import it from some Stimulus controller and load that controller lazily.
> Any tips for separation? I'm thinking of splitting things into partials and import them all in app.(s)css.
There are 2 reasons to separate your code: (A) performance (a smaller built app.css file) and (B) internal organization. I've talked a lot about part (A). But for (B), totally! Feel free to separate your main CSS into partials and then import from app.css - we do that internally here. Probably 90% of our CSS is done this way (they live in scss partials and are imported by app.scss). The last 10% are for features that are not on the main part of our site (e.g. challenges) and so we import them from a lazy stimulus controller.
Cheers!
Where do you set data-turbo-track when you use asset mapper instead of webpack? The only supported command - that is similar - is: importmap_script_attributes:
in: asset_mapper.yaml
But this only affects imports from the import map.
Neither other used script tags nor link tags...
Hey @nonplusultra ,
Seems you can do it with
importmap_script_attributesnow, see: https://symfony.com/doc/current/frontend/asset_mapper.html#framework-asset-mapper-importmap-script-attributesYou can run
bin/console conf:dump framework asset_mapperto see the example of configuration withdata-turbo-track: reload.Make sure you're updated to the latest AssetMapper version. I hope that helps!
Cheers!
Simply out of curiosity, why isn't the behavior behind the data-turbo-track="reload" attribute something that's done by default? Isn't this something you always want checked? Why is it optional?
Hey Ewald V.!
That's... actually a great question! There are two parts to this:
A) In Turbo, they need to know which things we consider as "assets" that should be tracked. So, they make us add this attribute. Maybe they could safely "guess" and use all link & script tags instead of forcing us to mark them. I'm not sure... there is likely an edge case where that wouldn't work.
B) In WebpackEncoreBundle, we could ALSO just "turn this on by default". We actually talked about this. I was against it, only because it feels weird to me to activate this data-turbo-track="reload" on every Symfony site by default regardless of whether they're using Turbo or no.
So, the end result is that this is something you need to activate... even though you always need it if you're using Turbo. We did update the recipe to have these lines, however. So you just need to uncomment them: https://github.com/symfony/...
Cheers!
Clear! Thanks for the detailed answer!
"Houston: no signs of life"
Start the conversation!