{"id":17997082,"url":"https://github.com/c0nw0nk/nginx-lua-minification-library","last_synced_at":"2025-03-26T04:31:02.091Z","repository":{"id":45645619,"uuid":"159107129","full_name":"C0nw0nk/Nginx-Lua-minification-library","owner":"C0nw0nk","description":"A compression and minification library to minify static or dynamic assets like HTML PHP outputs CSS style sheets JS Javascript all text/html or plain text mime types that nginx can output that the browser will read so they are small compressed and have white space removed as well as helping reduce bandwidth consumption since the files served from nginx webserver are now smaller.","archived":false,"fork":false,"pushed_at":"2023-03-21T18:56:19.000Z","size":17,"stargazers_count":23,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-21T05:22:23.730Z","etag":null,"topics":["bandwidth","cloudflare","compression","css","javascript","lua","luajit","nginx","nginx-lua","nginx-webserver","openresty","pagespeed","stylesheets","white-spaces"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/C0nw0nk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["C0nw0nk"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://paypal.me/wimbledonfc","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=ZH9PFY62YSD7U\u0026source=url"]}},"created_at":"2018-11-26T03:50:27.000Z","updated_at":"2024-12-05T14:30:40.000Z","dependencies_parsed_at":"2024-10-29T21:52:23.543Z","dependency_job_id":null,"html_url":"https://github.com/C0nw0nk/Nginx-Lua-minification-library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C0nw0nk%2FNginx-Lua-minification-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C0nw0nk%2FNginx-Lua-minification-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C0nw0nk%2FNginx-Lua-minification-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/C0nw0nk%2FNginx-Lua-minification-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/C0nw0nk","download_url":"https://codeload.github.com/C0nw0nk/Nginx-Lua-minification-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245589196,"owners_count":20640243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bandwidth","cloudflare","compression","css","javascript","lua","luajit","nginx","nginx-lua","nginx-webserver","openresty","pagespeed","stylesheets","white-spaces"],"created_at":"2024-10-29T21:16:53.539Z","updated_at":"2025-03-26T04:31:02.084Z","avatar_url":"https://github.com/C0nw0nk.png","language":"Lua","funding_links":["https://github.com/sponsors/C0nw0nk","https://paypal.me/wimbledonfc","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=ZH9PFY62YSD7U\u0026source=url"],"categories":[],"sub_categories":[],"readme":"# Nginx-Lua-minification-library\nA compression and minification library to minify static or dynamic assets like HTML PHP outputs CSS style sheets JS Javascript all text/html or plain text mime types that nginx can output that the browser will read so they are small compressed and have white space removed as well as helping reduce bandwidth consumption since the files served from nginx webserver are now smaller.\n\n\u003e Please note, this script will only remove comments, white spaces and breaklines from your code. So, this mean it will not \"rebuild\" your files in order to minify the code. If you want something similar, I recommend using [Pagespeed](https://developers.google.com/speed/pagespeed/module/ \"Pagespeed\") from Google\n\n# Information :\n\nI built this script to compress and keep the specified mime types outputs small and minify the bandwidth that my servers have to use when serving these files to users.\n\nIf you have any bugs issues or problems just post a Issue request.\n\nhttps://github.com/C0nw0nk/Nginx-Lua-minification-library/issues\n\nIf you fork or make any changes to improve this or fix problems please do make a pull request for the community who also use this. \n\nhttps://github.com/C0nw0nk/Nginx-Lua-minification-library/pulls\n\n# Usage :\n\nEdit settings inside `minify.lua` to add your own mime types or improve my regex. (Please share your soloutions and additions)\n\nhttps://github.com/C0nw0nk/Nginx-Lua-minification-library/blob/master/lua/minify/minify.lua#L69\n\nAdd this to your Nginx configuration folder.\n\n`nginx/conf/lua/minify`\n\nOnce installed into your `nginx/conf/` folder.\n\nAdd this to your HTTP block or it can be in a server or location block depending where you want this script to run for individual locations the entire server or every single website on the server.\n\n```\nheader_filter_by_lua_file conf/lua/minify/minify_header.lua\nbody_filter_by_lua_file conf/lua/minify/minify.lua;\n```\n\n### Example nginx.conf :\n\nThis will run for all websites on the nginx server\n\n```\nhttp {\n#nginx config settings etc\nheader_filter_by_lua_file conf/lua/minify/minify_header.lua\nbody_filter_by_lua_file conf/lua/minify/minify.lua;\n#more config settings and some server stuff\n}\n```\n\nThis will make it run for this website only\n\n```\nserver {\n#nginx config settings etc\nheader_filter_by_lua_file conf/lua/minify/minify_header.lua\nbody_filter_by_lua_file conf/lua/minify/minify.lua;\n#more config settings and some server stuff\n}\n```\n\nThis will run in this location block only\n\n```\nlocation / {\n#nginx config settings etc\nheader_filter_by_lua_file conf/lua/minify/minify_header.lua\nbody_filter_by_lua_file conf/lua/minify/minify.lua;\n#more config settings and some server stuff\n}\n```\n\n\n# Building your own regex rules to apply inside this script :\n\nUsing my code examples below copy and paste them to test and edit and build your own regex on the Lua demo site here :\n\nhttps://www.lua.org/cgi-bin/demo\n\n#### Examples :\n\n##### Basic :\n```\nlocal string = \"\u003cstyle\u003elol1/* ok lol */lol2\u003c/style\u003e\"\nlocal regex = \"\u003cstyle\u003e(.*)%/%*(.*)%*%/(.*)\u003c/style\u003e\"\nlocal replace_with = \"\u003cstyle\u003e%1%3\u003c/style\u003e\"\nlocal output = string.gsub(string, regex, replace_with)\nprint(output)\n```\n\n##### Advanced :\n```\nlocal add_to_string = [[added me!]]\nlocal string = [[\u003cstyle\u003elol1/* ok lol */lol2\u003c/style\u003e]] .. add_to_string .. [[\nhello world!\n]]\nlocal regex = \"\u003cstyle\u003e(.*)%/%*(.*)%*%/(.*)\u003c/style\u003e\"\nlocal replace_with = \"\u003cstyle\u003e%1%3\u003c/style\u003e\"\nlocal output = string.gsub(string, regex, replace_with)\nprint(output)\n```\n\n# Requirements :\nNONE! :D You only need Nginx + Lua to use my scripts.\n\n###### Where can you download Nginx + Lua ?\n\nOpenresty provide Nginx + Lua builds for Windows Linux etc here.\n\nhttps://openresty.org/en/download.html\n\nNginx4windows has Windows specific builds with Lua here.\n\nhttp://nginx-win.ecsds.eu/\n\nOr you can download the source code for Nginx here and compile Nginx yourself with Lua.\n\nhttps://nginx.org/en/download.html\n\n# About :\n\nI was inspired to create this because of Cloudflare feature \"Auto Minify\" https://www.cloudflare.com/\n```\nAuto Minify\n\nReduce the file size of source code on your website.\n\nWhat does Auto Minify do?\n\nAuto Minify removes unnecessary characters from your source code (like whitespace, comments, etc.) without changing its functionality.\n\nMinification can compress source file size which reduces the amount of data that needs to be transferred to visitors and thus improves page load times.\n```\n\nI love that feature so much ontop of having it enabled on all my Cloudflare proxied sites I decided to make it into a feature on my own servers so the traffic I send to cloudflare is also reduced in bandwidth too! (Every little helps right!)\n\nThank you to @Cloudflare for the inspiration and your community for all the love, A big thanks to the @openresty community you guys rock Lua rocks you are all so awesome!\n\nLets build a better internet together! Where Speed, Privacy, Security and Compression matter!\n\nHere are links to my favorite communities :)\n\nhttp://openresty.org/en/\n\nhttps://community.cloudflare.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0nw0nk%2Fnginx-lua-minification-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc0nw0nk%2Fnginx-lua-minification-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0nw0nk%2Fnginx-lua-minification-library/lists"}