Skip to content

Commit

Permalink
README update
Browse files Browse the repository at this point in the history
  • Loading branch information
jxmot committed Jun 8, 2022
1 parent fa6262a commit 955edf2
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# minimize-prep

This repository contains a PHP script that reads a file where HTML tags (`<script>` and `<link>`) are used for including CSS and Javascript files in a web page. As each CSS or JavaScript file tag is found the file contents are read and then appended to output file (CSS or JS).
This repository contains a PHP script that reads a file where HTML tags (`<script>` and `<link>`) are used for including CSS and Javascript files in a web page. As each CSS or JavaScript file tag is found the file contents are read and then appended to an appropriate output file (CSS or JS).

In any `<script>` and `<link>` tags where the resource is not local those will be skipped and their contents will not be appended to output files (CSS or JS).

The result are two files that are ready for *minimization*. However, minimization is not required. You can use this to combine your CSS and JS files in order to reduce the number of requests made by the browser to the server.

Expand Down Expand Up @@ -36,10 +38,10 @@ So this repository will use that folder structure in the example:
├── public_html
│ │
│   ├── css
│   │   └── example_*.css
│   │   └── *.css
│ │
│   ├── js
│   │   └── example_*.js
│   │   └── *.js
│ │
│   └── example.html
Expand All @@ -54,6 +56,8 @@ Now open `minprep.json`:
{
"input":"example.html",
"fileroot":"./public_html/",
"cssexclude": ["cssexcl"],
"jsexclude": ["jsexcl"],
"cssout": "./site.css",
"jsout": "./site.js",
"filecomment": true,
Expand All @@ -63,6 +67,13 @@ Now open `minprep.json`:

Please note that `"fileroot"` is set for use within this repository space. Edit it as needed for your project. But for now leave it as-is.

The remaining settings are:

* `"cssexclude": ["cssexcl"]` and `"jsexclude": ["jsexcl"]` - Each is an array of strings where each is compared against the current resource found in `./public_html/example.html`. If there is a *partial* match then that resource will be excluded from the `./site.css` or `./site.js` files.
* `"cssout": "./site.css"` and `"jsout": "./site.js"` - The path + file names of the resulting output files.
* `"filecomment": true` - For convenience, when `true` a commented line with the current resource file name will precede its contents.
* `"mkbash": true` - When `true` a file named `./rmvresources.sh` will be created. It will contain Linux `rm` commands for each of the resource files found.

# Run

```
Expand All @@ -76,19 +87,41 @@ Starting preparation...
Input: ./public_html/example.html
Files Root Path: ./public_html/
./site.css and ./site.js will be overwritten.
Creating ./rmvresources.sh file
CSS found - ./assets/css/example_1.css
CSS found - ./assets/css/example_2.css
CSS found - ./assets/css/example_3.css
JS found - ./assets/js/example_1.js
CSS found - assets/css/example_3.css
CSS exluded - <link rel="stylesheet" href="./assets/css/cssexclude_1.css" type="text/css" />
CSS exluded - <link rel="stylesheet" href="./assets/cssexcl/exclude_1.css" type="text/css" />
JS found - /assets/js/example_1.js
JS found - ./assets/js/example_2.js
JS found - ./assets/js/example_3.js
JS found - ./assets/js/example_4.js
JS exluded - <script src="/assets/js/jsexclude_1.js" type="text/javascript"></script>
JS exluded - <script src="/assets/jsexcl/exclude_1.js" type="text/javascript"></script>
Preparation Complete.
```

# Output

The current configuration will cause 3 files to be created:

* `site.css` and `site.js`
* `rmvresources.sh` - An optional bash script file that will contain Linux `rm` commands to delete the CSS and JSS *source* files that were used to create `site.css` and `site.js`. **USE THIS SCRIPT WITH CAUTION!!!**

To disable the creation of `rmvresources.sh` edit `minprep.json` and change `"mkbash"` to `false`.

# Important Things to Note

Commented out `<link>` or `<script>` tags must look like this:
Expand All @@ -113,7 +146,7 @@ src="path/to/some.js"
>
```

The paths in the `<link>` and `<script>` can be *relative* or *absolute*. The script will create path using `"fileroot"`in the `minprep.json` file.
The paths in the `<link>` and `<script>` can be *relative* or *absolute*. The script will create a path using `"fileroot"`in the `minprep.json` file.

Each time you run `minprep.php` it will **overwrite** the `site.css` and `site.js` files. And if `"mkbash"` is `true` in `minprep.json` then a *bash script* named `rmvresources.sh` will be created. Its purpose is to make removing the original CSS and JS easier. Although removing them is not required, it is your descision for your project.

Expand Down

0 comments on commit 955edf2

Please sign in to comment.