{"id":14965566,"url":"https://github.com/baraja-core/assets-loader","last_synced_at":"2025-10-25T11:32:01.423Z","repository":{"id":45031278,"uuid":"235367944","full_name":"baraja-core/assets-loader","owner":"baraja-core","description":"🚀 Smart asset loader for Nette framework.","archived":false,"fork":false,"pushed_at":"2024-06-09T20:17:23.000Z","size":92,"stargazers_count":7,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T07:05:14.840Z","etag":null,"topics":["assets-loader","baraja","cdn","invalidation","minification","nette-framework","php","register","solves"],"latest_commit_sha":null,"homepage":"https://php.baraja.cz","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baraja-core.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"janbarasek","custom":["https://brj.app","https://baraja.cz","https://php.baraja.cz"]}},"created_at":"2020-01-21T14:56:38.000Z","updated_at":"2024-07-03T22:05:29.000Z","dependencies_parsed_at":"2024-09-13T23:39:48.072Z","dependency_job_id":"99264afb-91a4-4ff2-838a-8b57ef414882","html_url":"https://github.com/baraja-core/assets-loader","commit_stats":{"total_commits":77,"total_committers":4,"mean_commits":19.25,"dds":"0.038961038961038974","last_synced_commit":"5c8714f6cbe75d37e3479880067f6fcd8f0059b3"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baraja-core%2Fassets-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baraja-core%2Fassets-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baraja-core%2Fassets-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baraja-core%2Fassets-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baraja-core","download_url":"https://codeload.github.com/baraja-core/assets-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238128654,"owners_count":19421076,"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":["assets-loader","baraja","cdn","invalidation","minification","nette-framework","php","register","solves"],"created_at":"2024-09-24T13:34:55.563Z","updated_at":"2025-10-25T11:32:01.013Z","avatar_url":"https://github.com/baraja-core.png","language":"PHP","funding_links":["https://github.com/sponsors/janbarasek","https://brj.app","https://baraja.cz","https://php.baraja.cz"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n  \u003cpicture\u003e\n    \u003csource media='(prefers-color-scheme: dark)' srcset='https://cdn.brj.app/images/brj-logo/logo-regular.png'\u003e\n    \u003cimg src='https://cdn.brj.app/images/brj-logo/logo-dark.png' alt='BRJ logo'\u003e\n  \u003c/picture\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://brj.app\"\u003eBRJ organisation\u003c/a\u003e\n\u003c/div\u003e\n\u003chr\u003e\n\nSmart assets loader (compatible with Nette framework)\n=====================================================\n\n![Integrity check](https://github.com/baraja-core/assets-loader/workflows/Integrity%20check/badge.svg)\n\nAsset loader is a simple library for automatically loading styles and scripts into your application.\n\nThis package solves:\n\n- Registration and loading of global styles and scripts\n- Definition of specific styles and scripts for specific pages so that a minimum of data is always transferred\n- Automatic compilation of styles and scripts directly on the server via PHP to maintain maximum performance and ease of use\n- Automatic cache management and invalidation\n\nThis whole package (as well as the rest of the [Baraja ecosystem](https://github.com/baraja-core)) has been designed for simple and elegant use. It solves most complex issues internally, so you can easily build large applications effortlessly.\n\n📦 Installation \u0026 Basic Usage\n-----------------------------\n\nThis package can be installed using [Package Manager](https://github.com/baraja-core/package-manager) which is also part of the Baraja [Sandbox](https://github.com/baraja-core/sandbox). If you are not using it, you will have to install the package manually using this guide.\n\nA model configuration can be found in the `common.neon` file inside the root of the package.\n\nTo manually install the package call Composer and execute the following command:\n\n```shell\n$ composer require baraja-core/assets-loader\n```\n\nIf the automatic installation fails or is not available, register the extension in your `common.neon` file:\n\n```yaml\nextensions:\n   assetsLoader: Baraja\\AssetsLoader\\LoaderExtension\n```\n\nIn the project's `common.neon` you have to define basic project assets. A fully working example of configuration can be found in the `common.neon` file inside this package. You can define the configuration simply using `assetsLoader` extension.\n\n**Important:** Verify that your project `www/.htaccess` does not block the return of `css` and `js` files from PHP.\n\nBasic usage\n-----------\n\nAll styles and scripts are divided into 2 categories:\n\n- Global (available for all pages or for a group of pages)\n- Local (only available for one specific page / route)\n\nPlace the styles and scripts in the project directory `www/assets`. The internal structure can be arbitrary.\n\nWithin your project `common.neon` file, simply define the location of each asset.\n\n\u003e **TIP:**\n\u003e\n\u003e Assets can also be declared as a URL from a CDN server (for example [Baraja CDN](https://cdn.baraja.cz)). In this case, the CDN paths will be listed directly in the source code.\n\u003e\n\u003e This type of asset loading is suitable for files that do not change their content over time because they are not managed by the Assets loader.\n\nExample of a basic definition:\n\n```yaml\nassetsLoader:\n   routing:\n      *:\n         - https://unpkg.com/bootstrap/dist/css/bootstrap.min.css\n         - css/global.css\n         - js/global.js\n      Front:Homepage:default:\n         - js/welcome-form.js\n      Front:Contact:default:\n         - css/contact.css\n         - js/contact.js\n      Service:*:\n         - css/service.css\n```\n\nEnforce format specification\n----------------------------\n\n**Important:**\n\nThe format of the file is derived automatically according to the suffix (for example `.css`). If for any reason (for example, when loading fonts from a CDN) you cannot specify a format, you can pass it as a key and value.\n\nFor example (the key is the path to the asset, the value of the field is a supported format):\n\n```yaml\nassetsLoader:\n   routing:\n      *:\n         'https://fonts.googleapis.com/css?family=Hind+Siliguri|Poppins:700\u0026display=swap': css\n```\n\nRouting rule\n------------\n\nThe routing rule is specified either as an absolute routing path (based on [Nette routing](https://github.com/nette/routing) rules), but an asterisk symbolic path can also be used.\n\nThe `*` rule always matches everything (all modules, presenters and actions).\n\nThe `Front:*` rule matches all presenters and actions within the same module.\n\nThe `Front:Service:*` rule matches all actions within the same presenter.\n\nThe `Front:Service:default` rule matches only one specific action.\n\nQuery parameters in the URL and other parameters do not affect routing rules. Only the static route from the Nette router is evaluated. Routing information is cached to maintain the best performance.\n\nOperation in the presenter\n--------------------------\n\nIn BasePresenter, create an instance of the service, pass it to the template, where it can be easily rendered. The whole logic was kept so that it was enough to simply register the service and the internal logic worked automatically.\n\n```php\nabstract class BasePresenter extends \\App\\Presenters\\BasePresenter\n{\n   #[Inject]\n   public Api $assetsLoader;\n\n   public function startup(): void\n   {\n      parent::startup();\n      $this-\u003etemplate-\u003eassetsLoader = $this-\u003eassetsLoader-\u003egetHtmlInit($this-\u003egetAction(true));\n   }\n```\n\nThe `getHtmlInit()` method automatically returns the entire rendered header content as HTML. The `$this-\u003egetAction(true)` method is available directly in the Presenter and returns the current route as an absolute path.\n\nThen simply type the contents of the header in `@layout.latte`:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n   \u003chead\u003e\n      \u003cmeta charset=\"utf-8\"\u003e\n      {$assetsLoader ?? ''|noescape}\n```\n\nThe rest works automatically.\n\nAsset minification and compilation\n----------------------------------\n\nThe package automatically compiles and minimizes all assets on the output.\n\nBefore returning an HTTP response, caching HTTP headers and other logic are automatically set to optimize retrieval. At the same time, the package contains ready-made automatic minifiers (services implementing the `Baraja\\AssetsLoader\\Minifier\\AssetMinifier` interface), which can reduce the data size of CSS and JS files.\n\nA modified version of the [JShrink](https://github.com/tedious/JShrink) library for PHP is used for minification, so you don't need any other applications on the server.\n\nCache handling\n--------------\n\nBefore returning the rendered HTML to the header, the library automatically detects the time of the last change to any returned file. According to this change, a checksum is then calculated, which is passed as a query parameter with the version.\n\nChange detection is performed in each request and only meta information from the filesystem is read (super fast method), therefore even if the file is changed directly on the server (or by some script), the cache is automatically invalidated immediately.\n\nAdding a query parameter to the URL will cause a new asset to be downloaded (because the browser will not have the contents of the original file in its internal cache) and the assets will behave the original way again.\n\n**Warning:** File content change detection is not performed for absolute URLs because real-time change cannot be detected.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaraja-core%2Fassets-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaraja-core%2Fassets-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaraja-core%2Fassets-loader/lists"}