-
Notifications
You must be signed in to change notification settings - Fork 1
Serve minified static assets and stop blocking HTML parsing #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mamico
wants to merge
2
commits into
main
Choose a base branch
from
minify-and-defer-static-js
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Minified assets | ||
| on: [push] | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # git checkout | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| # node setup (esbuild is fetched on the fly via npx) | ||
| - name: Set up Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| # regenerate redturtle_chefcookie(.tech).min.js and styles.min.css | ||
| # and fail if that produces a diff: it means a source file was | ||
| # edited without regenerating its minified counterpart. | ||
| - name: check minified assets are up to date | ||
| run: make check-minified | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| STATIC_DIR = src/redturtle/chefcookie/browser/static | ||
| ESBUILD = npx --yes esbuild@0.28.1 | ||
|
|
||
| JS_SOURCES = \ | ||
| $(STATIC_DIR)/redturtle_chefcookie.js \ | ||
| $(STATIC_DIR)/redturtle_chefcookie_tech.js | ||
| JS_MINIFIED = $(JS_SOURCES:.js=.min.js) | ||
|
|
||
| CSS_SOURCES = $(STATIC_DIR)/styles.css | ||
| CSS_MINIFIED = $(CSS_SOURCES:.css=.min.css) | ||
|
|
||
| .PHONY: minify minify-js minify-css check-minified | ||
|
|
||
| minify: minify-js minify-css | ||
|
|
||
| minify-js: | ||
| @for src in $(JS_SOURCES); do \ | ||
| out="$${src%.js}.min.js"; \ | ||
| echo "minifying $$src -> $$out"; \ | ||
| $(ESBUILD) $$src --minify --outfile=$$out; \ | ||
| done | ||
|
|
||
| minify-css: | ||
| @for src in $(CSS_SOURCES); do \ | ||
| out="$${src%.css}.min.css"; \ | ||
| echo "minifying $$src -> $$out"; \ | ||
| $(ESBUILD) $$src --minify --outfile=$$out; \ | ||
| done | ||
|
|
||
| # Regenerates the minified assets and fails if that changes anything that | ||
| # is not already committed: catches the case where someone edited a source | ||
| # file (redturtle_chefcookie.js, redturtle_chefcookie_tech.js, styles.css) | ||
| # without regenerating its .min counterpart. | ||
| # NOTE: this compares file *content* (git diff), not modification times: | ||
| # git does not preserve mtimes on checkout, so an mtime-based check would | ||
| # always "pass" right after a fresh clone/checkout in CI regardless of | ||
| # which file was actually edited last. | ||
| check-minified: minify | ||
| git diff --exit-code -- $(JS_MINIFIED) $(CSS_MINIFIED) |
69 changes: 69 additions & 0 deletions
69
src/redturtle/chefcookie/browser/static/redturtle_chefcookie.min.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| class redturtlechefcookie extends chefcookie{showSettings(){this.logTracking("settings_open");let e=document.querySelector(".chefcookie__settings-container");e.classList.add("chefcookie__settings-container--visible"),e.style.minHeight=e.scrollHeight+"px",setTimeout(()=>{e.classList.contains("chefcookie__settings-container--visible")&&(e.style.height="auto"),e.focus()},this.animationSpeed),this.fixMaxHeight()}acceptAllScripts(){let e=[];this.config.settings.forEach(i=>{i.scripts!==void 0&&Object.entries(i.scripts).forEach(([c,t])=>{this.accept(c,!1)})})}switchSettingsLabelsOpen(){document.querySelector(".chefcookie__button--accept").style.display="block",document.querySelector(".chefcookie__button--settings").style.display="none"}buildDom(){document.body.insertAdjacentHTML("afterbegin",` | ||
| <div id="cc-banner" class="chefcookie chefcookie--${this.config.style.layout} chefcookie--columns-${"columns"in this.config.style?this.config.style.columns:"auto"}${"scripts_selection"in this.config&&this.config.scripts_selection!==!1?" chefcookie--has-scripts":""} chefcookie--hidden"> | ||
| <div class="chefcookie__inner"> | ||
| <div class="chefcookie__box"> | ||
|
|
||
| <a data-cc-destroy href="#" class="close" title="${this.getLabel("close")}"></a> | ||
|
|
||
| <div class="chefcookie__message">${this.translate(this.config.message)}</div> | ||
| <div class="chefcookie__settings-container" id="chefcookie__settings" tabindex="0"> | ||
| <ul class="chefcookie__groups chefcookie__groups--count-${this.config.settings.length}"> | ||
| ${this.config.settings.map((e,i)=>` | ||
| <li class="chefcookie__group${e.cannot_be_modified?" chefcookie__group--disabled":""}"> | ||
| <div class="chefcookie__group_wrapper"> | ||
| ${"scripts_selection"in this.config&&this.config.scripts_selection==="collapse"&&"scripts"in e&&Object.keys(e.scripts).length>0&&Object.keys(e.scripts)[0].indexOf("dummy_")===-1?` | ||
| <a href="#" class="chefcookie__group-collapse">${this.getLabel("group_open")!=""?this.getLabel("group_open"):this.getLabel("settings_open")}</a> | ||
| `:""} | ||
| <label class="chefcookie__group-label" for="chefcookie_group_${i}"> | ||
| <h3 class="chefcookie__group-label-text"> | ||
| ${this.translate(e.title)} | ||
| </h3> | ||
| <span class="show-info" aria-controls="chefcookie_group_${i}_description"> | ||
|
|
||
| ${"description"in e&&e.description!=""?` | ||
| <span class="chefcookie__group-description" id="chefcookie_group_${i}_description">${this.translate(e.description)}</span> | ||
| `:""} | ||
| </span> | ||
|
|
||
| <input${e.cannot_be_modified?' disabled="disabled"':""} class="chefcookie__group-checkbox" data-status="${this.isCheckboxActiveForGroup(i)}" id="chefcookie_group_${i}" type="checkbox" role="checkbox" aria-describedby="chefcookie_group_${i}_description" aria-checked="${this.isCheckboxActiveForGroup(i)===2?"true":"false"}" name="chefcookie_group[]" value="${i}"${this.isCheckboxActiveForGroup(i)===2?' checked="checked"':""} /> | ||
| <span class="chefcookie__group-checkbox-icon"></span> | ||
| </label> | ||
|
|
||
|
|
||
|
|
||
|
|
||
| </div> | ||
|
|
||
| ${"scripts_selection"in this.config&&this.config.scripts_selection!==!1&&"scripts"in e&&Object.keys(e.scripts).length>0&&Object.keys(e.scripts)[0].indexOf("dummy_")===-1?` | ||
| <ul class="chefcookie__scripts chefcookie__scripts--count-${Object.keys(e.scripts).length}${this.config.scripts_selection!=="collapse"?" chefcookie__scripts--visible":""}"> | ||
| ${Object.keys(e.scripts).map(c=>` | ||
| <li class="chefcookie__script${e.cannot_be_modified?" chefcookie__script--disabled":""}"> | ||
| <div class="chefcookie__script_wrapper"> | ||
| <label class="chefcookie__script-label" for="chefcookie_script_${i}_${c}"> | ||
| <input${e.cannot_be_modified?' disabled="disabled"':""} class="chefcookie__script-checkbox" id="chefcookie_script_${i}_${c}" aria-describedby="chefcookie_script_${i}_${c}_description" type="checkbox" name="chefcookie_script[]" value="${i}|${c}"${this.isCheckboxActiveForProvider(i,c)?' checked="checked"':""} /> | ||
| <span class="chefcookie__script-title">${typeof e.scripts[c]=="object"&&e.scripts[c]!==null&&"title"in e.scripts[c]&&e.scripts[c].title!=""?this.translate(e.scripts[c].title):c}</span> | ||
| <span class="chefcookie__script-checkbox-icon"></span> | ||
| </label> | ||
| ${typeof e.scripts[c]=="object"&&e.scripts[c]!==null&&"description"in e.scripts[c]&&e.scripts[c].description!=""?'<div class="chefcookie__script-description"><a href="#" class="chefcookie__script-description-collapse" aria-hidden="true" aria-controls="chefcookie_script_'+i+"_"+c+'_description" aria-label="'+this.getLabel("details_open")+'">'+this.getLabel("details_open")+'</a><div class="chefcookie__script-description-content" id="chefcookie_script_'+i+"_"+c+'_description">'+this.translate(e.scripts[c].description)+"</div></div>":""} | ||
| </div> | ||
| </li> | ||
| `).join("")} | ||
| </ul> | ||
| `:""} | ||
|
|
||
| </li> | ||
| `).join("")} | ||
| </ul> | ||
| </div> | ||
| <div class="chefcookie__buttons chefcookie__buttons--count-${"show_decline_button"in this.config&&this.config.show_decline_button===!0?"3":"2"}"> | ||
| <a href="#chefcookie__decline" class="chefcookie__button chefcookie__button--decline" role="button">${this.getLabel("decline")}</a> | ||
| <a href="#chefcookie__accept_all" data-cc-accept-all class="chefcookie__button chefcookie__button--accept_all" role="button">${this.getLabel("accept_all")}</a> | ||
|
|
||
| <a href="#chefcookie__settings" class="chefcookie__button chefcookie__button--settings" aria-controls="chefcookie__settings" role="button">${this.getLabel("settings_open")}</a> | ||
| <a href="#chefcookie__accept" style="display:none" class="chefcookie__button chefcookie__button--accept" role="button">${this.getLabel("accept")}</a> | ||
|
|
||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `)}} |
48 changes: 48 additions & 0 deletions
48
src/redturtle/chefcookie/browser/static/redturtle_chefcookie_tech.min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.