Lesson 3.3: After a stylesheet change
"I changed the CSS and nothing happened" is the most common sentence in a theme course. The packed file, the cache block that holds its link and the browser's copy each remember the old version. This short lesson gives learners one routine that always works, and one rule they must not break: no version query on a link.
At a glance
| Course | Theme design |
| Module | Module 3: Stylesheets and scripts through the packer |
| Duration | 30 minutes (10 presenting, 20 exercise) |
| Level | Beginner |
| Audience | Designers and front-end developers |
| Prerequisites | Lesson 3.2 |
Learning objectives
After this lesson, learners can:
- name the three places that remember an old stylesheet and the cache that clears each;
- run the clear routine after a stylesheet or script change;
- force the browser to fetch the new file with a hard reload;
- explain why a
?v=query on a link is not used.
Trainer's notes
How to present it
Sources: Stylesheets and scripts for your site, after a change and Styling the administration, after a stylesheet change.
Three memories (4 minutes). Draw them on the board:
Remembers Cleared by the packed file php bin/php/ezcache.php --clear-id=ezjscore-packerthe link to it, in compiled templates and in cache blocks of the pagelayout --clear-tag=templateand--clear-id=template-blockthe browser's copy a hard reload (Ctrl+Shift+R, or Cmd+Shift+R on a Mac) With
AppendLastModifiedTime=enableda new file gets a new name anyway; the clears make sure the page links that new name.No version query (2 minutes). Do not add
?v=...to a stylesheet or script link: the modification time in the packed name already does that, and the project's rule forbids version queries. A browser that still shows the old look needs a hard reload.On a Velocity server (2 minutes). Velocity keeps its own response cache. On a server that runs it, one command does the whole routine after a stylesheet change:
php bin/php/console exp:velocity deploy --packer--packerclears the packed scripts and styles right before the template-block cache. Add--dry-runto see the steps first.New template files (2 minutes). A stylesheet change needs no
template-overrideclear; a new template file does (lesson 2.3).
Common questions
Why does the change show for me but not for a colleague? Your browser fetched the new file; theirs still holds the old one. A hard reload on their side.
Do I need all of this with the packer off? With level 0 each file is linked at its own address; the browser's copy is the main obstacle, so a hard reload is usually enough. The routine still works.
Why not clear all caches every time? It works, but on a real site it is slow and clears the content view cache for every page. Learn the targeted clear.
Pitfalls
- Clearing only the packer. The pagelayout's cache block still links the old name, which may no longer exist:
the page loses its styles. Clear
template-blocktoo. - Editing in the wrong design. The change was made in a file that the chain never reaches. Check with the page source which file the packed bundle came from (packer off, lesson 3.2).
- Testing behind a proxy or CDN. Their caches are outside Exponential; the trainer's lab should not have one.
Hands-on exercise
On your training installation, packer on.
In
training.cssof your design, change the breadcrumb's font size from0.9remto1.1rem. Save.Reload the page normally. Note whether the breadcrumb changed.
Read the stylesheet link in the page source and write down the file name.
Run the routine:
php bin/php/ezcache.php --clear-id=ezjscore-packer php bin/php/ezcache.php --clear-tag=template php bin/php/ezcache.php --clear-id=template-blockIf your lab is served by Velocity, also clear its response cache:
php bin/php/console exp:velocity cache clear --apply.Reload with a hard reload. Check the breadcrumb.
Read the stylesheet link again and compare its name with step 3.
If your lab runs on Velocity, run
php bin/php/console exp:velocity deploy --packer --dry-runand read the list of steps it would run. Do not run it without--dry-runon a shared server.Write the routine of step 4 on a card next to your keyboard.
Expected result
- Step 2: the change may or may not show, depending on caches and the browser.
- Step 5: the breadcrumb shows the new size.
- Step 6: the number between the underscores in the name is higher than in step 3.
- Step 7: the dry run lists the steps, among them the packer and template-block caches, and changes nothing.
- The trainer asks two learners to say the three memories and their clears without notes.
Quiz
- Which three caches does the routine clear after a stylesheet change?
- Why can the page lose all its styles if only the packer cache is cleared?
- A colleague still sees the old color after your routine. What should they do?
A. Add
?v=2to the link B. Clear all caches again C. A hard reload D. Restart the database - Which command does the whole routine on a Velocity server?
- True or false: a stylesheet change needs the
template-overridecache cleared.
Answers
ezjscore-packer, the template cache andtemplate-block(Stylesheets and scripts for your site).- A cache block in the pagelayout still links the old packed file name, which no longer exists.
- C. Version queries are not used; the modification time in the name already changes it.
php bin/php/console exp:velocity deploy --packer.- False. Only a new template file needs it.
Further reading
- Stylesheets and scripts for your site: the checklist.
- Caches: every cache and its id.
- Velocity response cache: the extra cache on Velocity servers.
Related pages
- Module 3: Stylesheets and scripts through the packer
- Theme design: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.