Lesson 3.2: The ezjscore packer
The packer turns the lists of lesson 3.1 into as few files as possible, minifies them and puts the modification time into each file name. With it off, every file is linked on its own, which is easier to debug. Designers switch between the two many times a day; this lesson makes them confident about which mode they are in and why.
At a glance
| Course | Theme design |
| Module | Module 3: Stylesheets and scripts through the packer |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Designers and front-end developers |
| Prerequisites | Lesson 3.1 |
Learning objectives
After this lesson, learners can:
- describe what the packer does at levels 0, 1, 2 and 3;
- tell from the page source whether the packer is on;
- switch it off and on for one siteaccess with
[eZJSCore] Packer; - find a packed file on disk and read the modification time in its name.
Trainer's notes
How to present it
Sources: Stylesheets and scripts for your site, the packer
and extension/ezjscore/settings/ezjscore.ini (show the file on the projector).
What it does (5 minutes). The levels, as the code applies them:
Level Result 0 no packing: each file is linked at its own address 1 the files of one call are combined into one file 2 combined and passed through the optimizers ( JavaScriptOptimizer[],CssOptimizer[])3 as 2, with the stylesheet optimizer's further steps Stylesheets default to level 3, scripts to level 2.
Who decides (4 minutes).
ezjscore.ini [eZJSCore] Packeris commented out by default; then the packer followssite.ini [TemplateSettings] DevelopmentMode:enabledmeans level 0,disabled(the default) means packing. SetPacker=disabled(or0) to force it off, or a number0to3to force a level.The name (3 minutes).
[Packer] AppendLastModifiedTime=enabled: the newest modification time of the files is part of the packed file's name, like<hash>_<time>_all.css. A changed file gives a new name, so browsers fetch it although packed files are cached for a long time. The packed files live under the installation's cache directory, inpublic/stylesheets/andpublic/javascript/.Other hosts (2 minutes).
[Packer] CustomHosts[.css]and[.js]serve packed files from another host. Mention it; it is a hosting decision.
Common questions
Why does the page link the file twice with different names after an edit? It does not; the old name is in a cached page or a cache block. Lesson 3.3 clears the right caches.
Should production run with DevelopmentMode=enabled? No. It switches packing off and serves every file
separately. Keep it for development siteaccesses.
Where do I see what was packed? With debug output on, the debug report has a section "CSS/JS files loaded with 'ezjscPacker' during request" listing each packed file and its level.
Pitfalls
- Switching the packer for every siteaccess. Use the siteaccess scope; the administration should stay packed.
- Editing the packed file. It is generated and replaced at the next change. Edit the source in the design.
- Mixing up the two settings files.
Packeris inezjscore.ini,DevelopmentModeinsite.ini.
Hands-on exercise
On your training installation, <site> drawn by training_theme.
Open a page of
<site>and its page source. Write down the<link rel="stylesheet">and<script>elements: how many are there, and what do their file names look like?Switch the packer off for your siteaccess only:
php bin/php/console exp:ini set ezjscore.ini/eZJSCore/Packer disabled siteaccess:<site> php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-tag=template php bin/php/ezcache.php --clear-id=template-blockReload the page source. Write down the stylesheet and script elements again and compare with step 1.
Open
training.cssthrough its link: it is your file exactly as written.Switch the packer back on by removing the setting:
php bin/php/console exp:ini rem ezjscore.ini/eZJSCore/Packer siteaccess:<site> php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-tag=template php bin/php/ezcache.php --clear-id=template-blockReload the page source: you are back to the result of step 1.
Find the packed stylesheet on disk. Take its file name from the page source and search for it:
find var -name '<file name>'.Open the file in an editor: the rules of several stylesheets, minified, one after the other.
Read the number between the two underscores of the name. Run
stat -c %Yon yourtraining.cssand on the other source stylesheets and compare.
Expected result
- Step 1: one packed stylesheet link for the head list and one packed script for the body list, with long hashed
names ending in
_all.cssand.js. - Step 3: one link per source file, at the files' own addresses in the design folders.
- Step 9: the number in the name is the newest modification time among the source files of that bundle.
- The trainer checks that every learner ends with the packer back on (
exp:ini where ezjscore.ini/eZJSCore/Packer <site>shows no siteaccess entry).
Quiz
Packeris not set inezjscore.ini. What decides whether files are packed?- What does level 0 mean? A. Packed and minified B. Combined but not minified C. Each file linked on its own D. Files not loaded
- Why is the modification time part of the packed file's name?
- Which setting serves packed scripts from another host?
- A learner edits a packed file in the cache directory to fix a color. Why is that wrong?
Answers
site.ini [TemplateSettings] DevelopmentMode:enabledswitches packing off,disabledleaves it on.- C.
- So that a changed file gets a new name and browsers fetch it, although packed files are cached for a long time
(
[Packer] AppendLastModifiedTime=enabled). ezjscore.ini [Packer] CustomHosts[.js].- The packed file is generated; the next change or cache clear replaces it. The fix belongs in the source stylesheet.
Further reading
- Stylesheets and scripts for your site: the packer's settings in one table.
- ezjscore: the extension behind the packer.
- Performance and caching for websites: what the packer does for page speed.
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.