{"id":24236864,"url":"https://github.com/mohid123/ngx-script-optimizer","last_synced_at":"2026-05-18T11:05:35.968Z","repository":{"id":270845169,"uuid":"909932378","full_name":"Mohid123/ngx-script-optimizer","owner":"Mohid123","description":"Script Optimizer Component for Angular v15+.","archived":false,"fork":false,"pushed_at":"2025-01-07T17:18:22.000Z","size":163,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T14:49:50.654Z","etag":null,"topics":["angular","angular-performance","angular-script-optimization","angular-speed","code-splitting","script-optimization","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ngx-script-optimizer","language":"TypeScript","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/Mohid123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2024-12-30T05:03:51.000Z","updated_at":"2025-01-07T17:18:26.000Z","dependencies_parsed_at":"2025-03-04T14:49:46.380Z","dependency_job_id":"d814ac39-6145-41b3-8882-1535bb701e52","html_url":"https://github.com/Mohid123/ngx-script-optimizer","commit_stats":null,"previous_names":["mohid123/ngx-script-optimizer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Mohid123/ngx-script-optimizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohid123%2Fngx-script-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohid123%2Fngx-script-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohid123%2Fngx-script-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohid123%2Fngx-script-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mohid123","download_url":"https://codeload.github.com/Mohid123/ngx-script-optimizer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mohid123%2Fngx-script-optimizer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260221558,"owners_count":22976867,"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":["angular","angular-performance","angular-script-optimization","angular-speed","code-splitting","script-optimization","typescript"],"created_at":"2025-01-14T19:49:06.502Z","updated_at":"2026-05-18T11:05:30.935Z","avatar_url":"https://github.com/Mohid123.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NgxScriptOptimizer\n\n**A lightweight Angular library designed to supercharge your third-party script handling.**\n\n---\n\n### **Note**:\nSupports **Angular 15** onwards. Not compatible with versions older than Angular 15.\n\n---\n\n## Features 🎯\n\n### **Optimize Your Third-Party Scripts:**\nEffortlessly improve the performance and management of third-party JavaScript, whether inline or external, while minimizing Total Blocking Time (TBT) and First Contentful Paint (FCP) improving page speed and performance.\n\n### **Seamless Integration with SSR and CSR:**\nDesigned for both Server-Side Rendering (SSR) and Client-Side Rendering (CSR), ensuring compatibility and flexibility for modern web applications.\n\n### **Asynchronous and Efficient Loading:**\nSupports multiple loading strategies:\n- **Eager:** Runs scripts as soon as they are available.\n- **Lazy:** Defer execution until the page is fully loaded.\n- **Idle:** Leverages `requestIdleCallback` to execute when the main thread is free.\n- **Worker:** Runs scripts in a Web Worker for non-blocking execution.\n\n### **Customizable Script Placement:**\nChoose where scripts are appended (head or body), giving you full control over your HTML structure. Call scripts exclusively on a page to page basis or globally based on your need. The scripts are automatically removed from the DOM once the page is destroyed.\n\n### **Lightning Fast \u0026 Lightweight:**\nMinimal impact on your bundle size with a developer-friendly API that focuses on speed and simplicity.\n\n---\n\n## **Who Benefits from NgxScriptOptimizer?**\n\n### Industries That Rely Heavily on Third-Party Scripts:\n1. **E-Commerce:** Enhance loading speed for analytics, payment gateways, and dynamic content.\n2. **Media \u0026 Publishing:** Optimize ads, comments plugins, and embedded videos.\n3. **SaaS Platforms:** Load tracking tools and third-party SDKs efficiently.\n4. **Finance:** Ensure secure and performant integrations of banking APIs and fraud detection tools.\n5. **Education:** Optimize learning platforms with third-party integrations like video conferencing or quiz tools.\n\n---\n\n## **Installation**\n\n```bash\nnpm install ngx-script-optimizer\n```\n\n---\n\n## **Usage**\n\n### **Basic Example**\n\nImport the package and include it in your standalone Angular component:\n\n```typescript\nimport { ScriptOptimizerComponent } from 'ngx-script-optimizer';\n\n@Component({\n  selector: 'app-root',\n  standalone: true,\n  imports: [CommonModule, ScriptOptimizerComponent],\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\nexport class AppComponent {}\n```\n\nIn your HTML:\n\n```html\n\u003cngx-script-optimizer\n  src=\"https://example.com/api.js\"\n  (onLoad)=\"runAfterLoad()\"\n  renderStrategy=\"client\"\n  loadStrategy=\"lazy\"\n  appendTo=\"head\"\n  contentType=\"text/javascript\"\n\u003e\u003c/ngx-script-optimizer\u003e\n```\n\n---\n\n## **Detailed Examples**\n\n### **1. Server-Side Rendering (SSR)**\n##### **Note**: Please note that for SSR, only the `lazy` and `eager` loading strategies are available. For CSR all options are available.\nFor SSR, scripts are rendered and run on the server, becoming part of the initial HTML sent to the browser.\n\n```html\n\u003cngx-script-optimizer\n  [scriptContent]=\"'console.log(\\'SSR Script Executed\\');'\"\n  renderStrategy=\"server\"\n  loadStrategy=\"eager\"\n  appendTo=\"body\"\n  contentType=\"text/javascript\"\n\u003e\u003c/ngx-script-optimizer\u003e\n```\n\n### **2. Client-Side Rendering (CSR)**\n\n#### **Lazy Loading Example**\n\nLoad the script after the page content has finished loading. The `lazy` load strategy will attach the `defer` flag to the script tag:\n\n```html\n\u003cngx-script-optimizer\n  src=\"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js\"\n  renderStrategy=\"client\"\n  loadStrategy=\"lazy\"\n  appendTo=\"head\"\n  contentType=\"text/javascript\"\n  (onLoad)=\"console.log('Moment.js loaded')\"\n\u003e\u003c/ngx-script-optimizer\u003e\n```\n\n#### **Idle Loading Example**\nExecute the script when the browser's main thread is idle:\n\n```html\n\u003cngx-script-optimizer\n  [scriptContent]=\"'console.log(\\'Idle Script Executed\\');'\"\n  renderStrategy=\"client\"\n  loadStrategy=\"idle\"\n  appendTo=\"head\"\n  contentType=\"text/javascript\"\n\u003e\u003c/ngx-script-optimizer\u003e\n```\n\n#### **Web Worker Execution Example**\n\nRun a script in a Web Worker:\n##### **Note**: Please note that only the `scriptContent` attribute is currently compatible with the web worker option.\n```html\n\u003cngx-script-optimizer\n  [scriptContent]=\"`onmessage = function(e) {\n    const result = e.data.num1 * e.data.num2;\n    postMessage(result);\n  };`\"\n  renderStrategy=\"client\"\n  loadStrategy=\"worker\"\n  appendTo=\"body\"\n  contentType=\"text/javascript\"\n\u003e\u003c/ngx-script-optimizer\u003e\n```\n\n---\n\n## **Options**\n\n| Input            | Value            | Description                                                                 |\n|------------------|------------------|-----------------------------------------------------------------------------|\n| `scriptContent`  | `string`         | Inline JavaScript code to execute. Cannot be run simultaneoulsy with the `src` attribute.                                          |\n| `src`            | `string`         | External script URL (not supported in Web Worker mode). Cannot be run simultaneoulsy with the `scriptContent` attribute.                    |\n| `renderStrategy` | `server` / `client` | Determines where the script runs (SSR or CSR). Default value is `server`.                           |\n| `loadStrategy`   | `eager` / `lazy` / `idle` / `worker` | Controls when and how the script loads. Default value is `lazy`.                                     |\n| `appendTo`       | `head` / `body`  | Specifies where to attach the script in the DOM. Default value is `head`                         |\n| `contentType`    | `text/javascript` | Specifies the MIME type of the script. Default value is `text/javascript`                                     |\n| `(onLoad)`       | `function`       | Event triggered immediately after the script is executed. Note that the onLoad method cannot be used in conjunction with SSR as it can only be called on the client side.                            |\n| `integrity`       | `string`       | Optionally provide the script `integrity` attribute. |\n| `origin`       | `string`       | Optionally provide the script `crossorigin` attribute.  |\n\n---\n\n## **Default Values**\n- **Render Strategy:** `server`\n- **Load Strategy:** `lazy`\n- **Append To:** `head`\n- **Content Type:** `text/javascript`\n\n---\n\n## **Contributing**\n\nFeel free to contribute to this library! Raise issues, suggest features, or submit pull requests.\n\n---\n\n## **License**\n\nThis project is licensed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohid123%2Fngx-script-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohid123%2Fngx-script-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohid123%2Fngx-script-optimizer/lists"}