5.5 KiB
5.5 KiB
Project Structure
An outline of the project structure.
Directories and files outline
| File | Description |
|---|---|
| Root | |
index.html |
Main HTML file that loads the app. |
service-worker.js |
Service worker for offline and PWA support. |
manifest.json |
Manifest for PWA configuration. |
JavaScript (assets/js) |
Core functionality of the app. |
compression.js |
Handles the image compression logic. |
download.js |
Handles the download logic of the compressed images. |
events.js |
Event listeners and handlers. |
global.js |
Initializes global variables such as references to elements, form, states, etc. |
helpers.js |
Helper functions. |
ui.js |
User interface DOM manipulation. |
utilities.js |
Utility functions for various tasks and smaller types of processing. |
Vendor Libraries (assets/vendor) |
Third-party libraries, essential to the app's functionality. |
browser-image-compress.js |
A library for browser-side image compression. |
heic-to.js |
HEIC image decoder, allowing converting to other browser-friendly file types. |
jszip.js |
Handles zipping of image files for download. |
Images (assets/images) |
Static images for user interface and metatags. |
CSS (assets/css) |
App styling. |
fonts.css |
Font definitions. |
style.css |
Main styling of the user interface. |
variables.css |
Global CSS variables for dynamic color, sizing, font, etc. |
Fonts (assets/fonts) |
Font files. |
Basic App Flow
To better understand the app’s flow and file interactions, the outline below describes the general image optimization process.
index.htmllaunches the app.- The scripts are loaded in a specific order to initialize global variables, references, and dependencies that other scripts depend on.
vendorscripts.global.jsutilities.jshelpers.jsui.jscompression.jsdownload.jsevents.js
initApp()inevents.jsbinds events to interactive components inindex.htmland handles saving/restoring app settings.- When a user drops or selects an image, event handlers in
events.jscapture the input and trigger compression functions fromcompression.js. - Before compressing any images,
ui.jsparses and validates the selected options. To do so, many features fromutilities.jsare used to build theoptionsobject that are passed to the image compressor. - Input images go through
preProcessImage(file)incompression.jsto be decoded, ensuring compatibility withbrowser-image-compression.js, which serves as the main image compressor library in this app.- Image formats natively supported by browsers (JPG, PNG, WebP) typically don't need pre-processing and are passed through directly.
- HEIC images are pre-processed, as they are not natively supported by major browsers.
- AVIF is natively supported, but due to its already optimized nature, it is pre-processed to a lossy format to reduce the chance of the output file being larger than the original.
- The state of the image processing, such as
isCompressing,compressQueue, and more, are stored inglobal.js. - Once an image is processed,
handleCompressionResult(file, output)inhelpers.jsoutputs the compressed image on the user interface, where users can download individual images or all images as a zip, handled bydownload.js.