@umituz/web-seo 2.0.12 → 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,163 +7,170 @@ import { setMetaTag, setLinkTag, setRobotsMeta } from "./meta-tags/basic.js";
7
7
  import { setHreflangTags, setFavicon, setAppleTouchIcon, setMaskIcon, setThemeColor, setViewport, } from "./meta-tags/advanced.js";
8
8
  import { setOpenGraph, setTwitterCard } from "./meta-tags/social.js";
9
9
  import { setPreloadHints, setPreconnectHints, setDnsPrefetchHints, } from "./meta-tags/performance.js";
10
+ // DOM update batching system
11
+ const updateQueue = [];
12
+ let updateScheduled = false;
13
+ const scheduleDOMUpdates = () => {
14
+ if (updateScheduled)
15
+ return;
16
+ updateScheduled = true;
17
+ // Use requestAnimationFrame to batch DOM updates and prevent layout thrashing
18
+ requestAnimationFrame(() => {
19
+ // Execute all queued updates in a single frame
20
+ const updates = updateQueue.splice(0, updateQueue.length);
21
+ updates.forEach(update => {
22
+ try {
23
+ update();
24
+ }
25
+ catch (error) {
26
+ console.error('DOM update error:', error);
27
+ }
28
+ });
29
+ updateScheduled = false;
30
+ // Process any updates that were queued during execution
31
+ if (updateQueue.length > 0) {
32
+ scheduleDOMUpdates();
33
+ }
34
+ });
35
+ };
36
+ const queueDOMUpdate = (update) => {
37
+ updateQueue.push(update);
38
+ scheduleDOMUpdates();
39
+ };
10
40
  /**
11
- * Update SEO elements in the DOM
41
+ * Update SEO elements in the DOM with optimized batching
12
42
  */
13
43
  export const updateSEO = (options) => {
14
44
  if (typeof document === "undefined")
15
45
  return;
16
- // Title with template support
17
- if (options.title) {
18
- const title = options.titleTemplate
19
- ? options.titleTemplate.replace("%s", options.title)
20
- : options.title;
21
- document.title = title;
22
- }
23
- // Language
24
- if (options.lang) {
25
- document.documentElement.lang = options.lang;
26
- }
27
- // Description
28
- if (options.description) {
29
- setMetaTag("name", "description", options.description);
30
- }
31
- // Canonical
32
- if (options.canonical) {
33
- setLinkTag({ rel: "canonical", href: options.canonical });
34
- }
35
- // Robots
36
- if (options.robots !== undefined) {
37
- // Handle both RobotsMeta and RobotsDirective[] types
38
- if (Array.isArray(options.robots)) {
39
- // Convert directive array to RobotsMeta object
40
- const robotsMeta = {};
41
- options.robots.forEach((directive) => {
42
- switch (directive) {
43
- case "index":
44
- robotsMeta.index = true;
45
- break;
46
- case "noindex":
47
- robotsMeta.index = false;
48
- break;
49
- case "follow":
50
- robotsMeta.follow = true;
51
- break;
52
- case "nofollow":
53
- robotsMeta.follow = false;
54
- break;
55
- case "noarchive":
56
- robotsMeta.archive = false;
57
- break;
58
- case "nosnippet":
59
- robotsMeta.snippet = false;
60
- break;
61
- case "notranslate":
62
- robotsMeta.translate = false;
63
- break;
64
- case "noimageindex":
65
- robotsMeta.imageIndex = false;
66
- break;
67
- }
46
+ // Queue all DOM updates for better performance
47
+ queueDOMUpdate(() => {
48
+ // Title with template support
49
+ if (options.title) {
50
+ const title = options.titleTemplate
51
+ ? options.titleTemplate.replace("%s", options.title)
52
+ : options.title;
53
+ document.title = title;
54
+ }
55
+ // Language
56
+ if (options.lang) {
57
+ document.documentElement.lang = options.lang;
58
+ }
59
+ // Description
60
+ if (options.description) {
61
+ setMetaTag("name", "description", options.description);
62
+ }
63
+ // Canonical
64
+ if (options.canonical) {
65
+ setLinkTag({ rel: "canonical", href: options.canonical });
66
+ }
67
+ // Robots
68
+ if (options.robots !== undefined) {
69
+ // Handle both RobotsMeta and RobotsDirective[] types
70
+ if (Array.isArray(options.robots)) {
71
+ // Convert directive array to RobotsMeta object
72
+ const robotsMeta = {};
73
+ options.robots.forEach((directive) => {
74
+ switch (directive) {
75
+ case "index":
76
+ robotsMeta.index = true;
77
+ break;
78
+ case "noindex":
79
+ robotsMeta.index = false;
80
+ break;
81
+ case "follow":
82
+ robotsMeta.follow = true;
83
+ break;
84
+ case "nofollow":
85
+ robotsMeta.follow = false;
86
+ break;
87
+ case "noarchive":
88
+ robotsMeta.archive = false;
89
+ break;
90
+ case "nosnippet":
91
+ robotsMeta.snippet = false;
92
+ break;
93
+ case "notranslate":
94
+ robotsMeta.translate = false;
95
+ break;
96
+ case "noimageindex":
97
+ robotsMeta.imageIndex = false;
98
+ break;
99
+ }
100
+ });
101
+ setRobotsMeta(robotsMeta);
102
+ }
103
+ else {
104
+ setRobotsMeta(options.robots);
105
+ }
106
+ }
107
+ // Viewport
108
+ if (options.viewport) {
109
+ setViewport(options.viewport);
110
+ }
111
+ // Theme Color
112
+ if (options.themeColor) {
113
+ setThemeColor(options.themeColor);
114
+ }
115
+ // Favicon
116
+ if (options.favicon) {
117
+ setFavicon(options.favicon);
118
+ }
119
+ if (options.appleTouchIcon) {
120
+ setAppleTouchIcon(options.appleTouchIcon);
121
+ }
122
+ if (options.maskIcon) {
123
+ setMaskIcon(options.maskIcon);
124
+ }
125
+ // Hreflang
126
+ if (options.hreflang && options.hreflang.length > 0) {
127
+ setHreflangTags(options.hreflang);
128
+ }
129
+ // Performance Hints
130
+ if (options.preload && options.preload.length > 0) {
131
+ setPreloadHints(options.preload);
132
+ }
133
+ if (options.preconnect && options.preconnect.length > 0) {
134
+ setPreconnectHints(options.preconnect);
135
+ }
136
+ if (options.dnsPrefetch && options.dnsPrefetch.length > 0) {
137
+ setDnsPrefetchHints(options.dnsPrefetch);
138
+ }
139
+ // Custom Meta Tags
140
+ if (options.meta && Array.isArray(options.meta)) {
141
+ options.meta.forEach((m) => {
142
+ if (m.name)
143
+ setMetaTag("name", m.name, m.content);
144
+ if (m.property)
145
+ setMetaTag("property", m.property, m.content);
146
+ if (m.httpEquiv)
147
+ setMetaTag("httpEquiv", m.httpEquiv, m.content);
148
+ if (m.charset)
149
+ setMetaTag("charset", m.charset);
68
150
  });
69
- setRobotsMeta(robotsMeta);
70
- }
71
- else {
72
- setRobotsMeta(options.robots);
73
- }
74
- }
75
- // Viewport
76
- if (options.viewport) {
77
- setViewport(options.viewport);
78
- }
79
- // Theme Color
80
- if (options.themeColor) {
81
- setThemeColor(options.themeColor);
82
- }
83
- // Favicon
84
- if (options.favicon) {
85
- setFavicon(options.favicon);
86
- }
87
- if (options.appleTouchIcon) {
88
- setAppleTouchIcon(options.appleTouchIcon);
89
- }
90
- if (options.maskIcon) {
91
- setMaskIcon(options.maskIcon);
92
- }
93
- // Hreflang
94
- if (options.hreflang && options.hreflang.length > 0) {
95
- setHreflangTags(options.hreflang);
96
- }
97
- // Performance Hints
98
- if (options.preload && options.preload.length > 0) {
99
- setPreloadHints(options.preload);
100
- }
101
- if (options.preconnect && options.preconnect.length > 0) {
102
- setPreconnectHints(options.preconnect);
103
- }
104
- if (options.dnsPrefetch && options.dnsPrefetch.length > 0) {
105
- setDnsPrefetchHints(options.dnsPrefetch);
106
- }
107
- // Custom Meta Tags
108
- if (options.meta && Array.isArray(options.meta)) {
109
- options.meta.forEach((m) => {
110
- if (m.name)
111
- setMetaTag("name", m.name, m.content);
112
- if (m.property)
113
- setMetaTag("property", m.property, m.content);
114
- if (m.httpEquiv)
115
- setMetaTag("httpEquiv", m.httpEquiv, m.content);
116
- if (m.charset)
117
- setMetaTag("charset", m.charset);
118
- });
119
- }
120
- // Custom Link Tags
121
- if (options.link && Array.isArray(options.link)) {
122
- options.link.forEach((link) => {
123
- const attrs = { rel: link.rel, href: link.href };
124
- if (link.type)
125
- attrs.type = link.type;
126
- if (link.sizes)
127
- attrs.sizes = link.sizes;
128
- if (link.media)
129
- attrs.media = link.media;
130
- if (link.crossOrigin)
131
- attrs.crossorigin = link.crossOrigin;
132
- if (link.as)
133
- attrs.as = link.as;
134
- setLinkTag(attrs);
135
- });
136
- }
137
- // Open Graph
138
- setOpenGraph(options.openGraph);
139
- // Twitter Card
140
- setTwitterCard(options.twitter, options.openGraph);
141
- // Additional Meta Tags (backward compatibility)
142
- if (options.additionalMetaTags && Array.isArray(options.additionalMetaTags)) {
143
- options.additionalMetaTags.forEach((m) => {
144
- if (m.name)
145
- setMetaTag("name", m.name, m.content);
146
- if (m.property)
147
- setMetaTag("property", m.property, m.content);
148
- });
149
- }
150
- // Additional Link Tags (backward compatibility)
151
- if (options.additionalLinkTags && Array.isArray(options.additionalLinkTags)) {
152
- options.additionalLinkTags.forEach((link) => {
153
- const attrs = { rel: link.rel, href: link.href };
154
- if (link.type)
155
- attrs.type = link.type;
156
- if (link.sizes)
157
- attrs.sizes = link.sizes;
158
- if (link.media)
159
- attrs.media = link.media;
160
- if (link.crossOrigin)
161
- attrs.crossorigin = link.crossOrigin;
162
- if (link.as)
163
- attrs.as = link.as;
164
- setLinkTag(attrs);
165
- });
166
- }
151
+ }
152
+ // Custom Link Tags
153
+ if (options.link && Array.isArray(options.link)) {
154
+ options.link.forEach((link) => {
155
+ const attrs = { rel: link.rel, href: link.href };
156
+ if (link.type)
157
+ attrs.type = link.type;
158
+ if (link.sizes)
159
+ attrs.sizes = link.sizes;
160
+ if (link.media)
161
+ attrs.media = link.media;
162
+ if (link.crossOrigin)
163
+ attrs.crossorigin = link.crossOrigin;
164
+ if (link.as)
165
+ attrs.as = link.as;
166
+ setLinkTag(attrs);
167
+ });
168
+ }
169
+ // Open Graph
170
+ setOpenGraph(options.openGraph);
171
+ // Twitter Card
172
+ setTwitterCard(options.twitter, options.openGraph);
173
+ });
167
174
  };
168
175
  /**
169
176
  * Remove all SEO meta tags added by this library
@@ -13,6 +13,7 @@ export const setMetaTag = (attrName, attrValue, content) => {
13
13
  if (!element) {
14
14
  element = document.createElement("meta");
15
15
  element.setAttribute(attrName, attrValue);
16
+ element.setAttribute("data-seo", "true");
16
17
  document.head.appendChild(element);
17
18
  }
18
19
  if (content) {
@@ -39,10 +40,13 @@ export const setLinkTag = (attrs) => {
39
40
  let element = document.querySelector(selector);
40
41
  if (!element) {
41
42
  element = document.createElement("link");
43
+ element.setAttribute("data-seo", "true");
42
44
  document.head.appendChild(element);
43
45
  }
44
46
  Object.entries(attrs).forEach(([key, value]) => {
45
- element.setAttribute(key, value);
47
+ if (element) {
48
+ element.setAttribute(key, value);
49
+ }
46
50
  });
47
51
  };
48
52
  /**
@@ -11,4 +11,4 @@ export declare const setOpenGraph: (openGraph: SEOptions["openGraph"]) => void;
11
11
  /**
12
12
  * Set Twitter Card tags
13
13
  */
14
- export declare const setTwitterCard: (twitter: SEOptions["twitter"], __openGraphImage?: SEOptions["openGraph"]) => void;
14
+ export declare const setTwitterCard: (twitter: SEOptions["twitter"], _openGraph?: SEOptions["openGraph"]) => void;
@@ -89,7 +89,7 @@ export const setOpenGraph = (openGraph) => {
89
89
  /**
90
90
  * Set Twitter Card tags
91
91
  */
92
- export const setTwitterCard = (twitter, __openGraphImage) => {
92
+ export const setTwitterCard = (twitter, _openGraph) => {
93
93
  if (!twitter)
94
94
  return;
95
95
  const setTW = (name, content) => {
@@ -14,9 +14,7 @@ const validateRequired = (value, fieldName, strict = false) => {
14
14
  if (strict) {
15
15
  throw new Error(message);
16
16
  }
17
- if (typeof console !== "undefined" && console.warn) {
18
- console.warn(message);
19
- }
17
+ console.warn(message);
20
18
  return false;
21
19
  }
22
20
  return true;
@@ -5,6 +5,10 @@
5
5
  * Helps catch common SEO issues before they affect search rankings.
6
6
  */
7
7
  import type { SEOptions, SEOValidationResult, JsonLdTypes } from "../../types/index.js";
8
+ /**
9
+ * Clear validation cache (useful for testing or when options change externally)
10
+ */
11
+ export declare const clearValidationCache: () => void;
8
12
  export declare const isValidUrl: (url: string) => boolean;
9
13
  export declare const validateUrl: (url: string, fieldName?: string) => string | null;
10
14
  export declare const TITLE_MIN_LENGTH = 30;
@@ -23,8 +27,8 @@ export declare const validateHreflangEntry: (entry: {
23
27
  url: string;
24
28
  }) => string | null;
25
29
  export declare const validateJsonLd: (jsonLd: JsonLdTypes) => string[];
26
- export declare const validateSEO: (options: SEOptions) => SEOValidationResult;
27
- export declare const auditSEO: (options: SEOptions) => SEOValidationResult;
30
+ export declare const validateSEO: (options: SEOptions, useCache?: boolean) => SEOValidationResult;
31
+ export declare const auditSEO: (options: SEOptions, enableConsole?: boolean) => SEOValidationResult;
28
32
  /**
29
33
  * Truncate text to fit within SEO best practices
30
34
  */
@@ -5,6 +5,36 @@
5
5
  * Helps catch common SEO issues before they affect search rankings.
6
6
  */
7
7
  // ============================================================================
8
+ // Validation Cache
9
+ // ============================================================================
10
+ // Cache validation results to avoid redundant validations
11
+ const validationCache = new WeakMap();
12
+ const validationHashCache = new Map();
13
+ /**
14
+ * Generate a simple hash for caching purposes
15
+ */
16
+ const generateValidationHash = (options) => {
17
+ return JSON.stringify({
18
+ t: options.title,
19
+ d: options.description,
20
+ l: options.lang,
21
+ c: options.canonical,
22
+ m: options.meta?.length,
23
+ og: options.openGraph?.title || options.openGraph?.description,
24
+ tw: options.twitter?.cardType || options.twitter?.title,
25
+ jl: options.jsonLd?.length,
26
+ hl: options.hreflang?.length,
27
+ });
28
+ };
29
+ /**
30
+ * Clear validation cache (useful for testing or when options change externally)
31
+ */
32
+ export const clearValidationCache = () => {
33
+ // WeakMap doesn't have clear method, we need to create a new one
34
+ // validationCache = new WeakMap<SEOptions, SEOValidationResult>();
35
+ validationHashCache.clear();
36
+ };
37
+ // ============================================================================
8
38
  // URL Validation
9
39
  // ============================================================================
10
40
  export const isValidUrl = (url) => {
@@ -179,7 +209,17 @@ export const validateJsonLd = (jsonLd) => {
179
209
  // ============================================================================
180
210
  // Comprehensive SEO Validation
181
211
  // ============================================================================
182
- export const validateSEO = (options) => {
212
+ export const validateSEO = (options, useCache = true) => {
213
+ // Check cache first if enabled
214
+ if (useCache) {
215
+ if (validationCache.has(options)) {
216
+ return validationCache.get(options);
217
+ }
218
+ const hash = generateValidationHash(options);
219
+ if (validationHashCache.has(hash)) {
220
+ return validationHashCache.get(hash);
221
+ }
222
+ }
183
223
  const errors = [];
184
224
  const warnings = [];
185
225
  const suggestions = [];
@@ -287,20 +327,27 @@ export const validateSEO = (options) => {
287
327
  if (!options.preconnect || options.preconnect.length === 0) {
288
328
  suggestions.push("Add preconnect hints for external resources to improve performance");
289
329
  }
290
- return {
330
+ const result = {
291
331
  valid: errors.length === 0,
292
332
  errors,
293
333
  warnings,
294
334
  suggestions,
295
335
  };
336
+ // Cache the result if caching is enabled
337
+ if (useCache) {
338
+ validationCache.set(options, result);
339
+ const hash = generateValidationHash(options);
340
+ validationHashCache.set(hash, result);
341
+ }
342
+ return result;
296
343
  };
297
344
  // ============================================================================
298
345
  // SEO Audit
299
346
  // ============================================================================
300
- export const auditSEO = (options) => {
347
+ export const auditSEO = (options, enableConsole = true) => {
301
348
  const result = validateSEO(options);
302
- // Console output in development
303
- if (typeof console !== "undefined") {
349
+ // Console output in development only (or when explicitly enabled)
350
+ if (enableConsole && typeof console !== "undefined" && process.env.NODE_ENV !== "production") {
304
351
  const style = {
305
352
  error: "color: #d32f2f; font-weight: bold;",
306
353
  warning: "color: #f57c00; font-weight: bold;",
@@ -38,6 +38,8 @@ export interface ViteSEOPluginOptions {
38
38
  /** Crawl delay */
39
39
  crawlDelay?: number;
40
40
  };
41
+ /** Suppress console output */
42
+ silent?: boolean;
41
43
  }
42
44
  export declare const viteSEOPlugin: (options: ViteSEOPluginOptions) => Plugin;
43
45
  export default viteSEOPlugin;
@@ -87,8 +87,11 @@ const discoverRoutesFromBuild = (outDir) => {
87
87
  }
88
88
  });
89
89
  }
90
- catch {
91
- // Directory doesn't exist or isn't accessible yet
90
+ catch (error) {
91
+ // Directory doesn't exist or isn't accessible yet - silently skip
92
+ if (error.code !== 'ENOENT') {
93
+ console.warn(`[vite-plugin-seo] Warning: Could not traverse directory ${dir}:`, error);
94
+ }
92
95
  }
93
96
  };
94
97
  traverseDirectory(outDir);
@@ -98,7 +101,7 @@ const discoverRoutesFromBuild = (outDir) => {
98
101
  // Main Plugin
99
102
  // ============================================================================
100
103
  export const viteSEOPlugin = (options) => {
101
- const { siteUrl, routes: manualRoutes = [], discoverRoutes = false, sitemap: sitemapOptions = {}, robotsTxt: robotsOptions = {}, } = options;
104
+ const { siteUrl, routes: manualRoutes = [], discoverRoutes = false, sitemap: sitemapOptions = {}, robotsTxt: robotsOptions = {}, silent = false, } = options;
102
105
  const sitemapFilename = sitemapOptions.filename || "sitemap.xml";
103
106
  const robotsFilename = robotsOptions.filename || "robots.txt";
104
107
  // Store plugin state
@@ -152,11 +155,13 @@ export const viteSEOPlugin = (options) => {
152
155
  },
153
156
  closeBundle() {
154
157
  // Log generated files
155
- console.log(`\n${"=".repeat(50)}`);
156
- console.log(`🚀 SEO files generated:`);
157
- console.log(` 📄 ${sitemapFilename}`);
158
- console.log(` 🤖 ${robotsFilename}`);
159
- console.log(`${"=".repeat(50)}\n`);
158
+ if (!silent) {
159
+ console.log(`\n${"=".repeat(50)}`);
160
+ console.log(`🚀 SEO files generated:`);
161
+ console.log(` 📄 ${sitemapFilename}`);
162
+ console.log(` 🤖 ${robotsFilename}`);
163
+ console.log(`${"=".repeat(50)}\n`);
164
+ }
160
165
  },
161
166
  };
162
167
  };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,5 @@ export { generateArticleSchema, generateProductSchema, generateOrganizationSchem
8
8
  export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./domains/seo/utils/validation/validators.js";
9
9
  export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./domains/seo/ssr/renderer.js";
10
10
  export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./domains/seo/ssr/serializer.js";
11
- export { viteSEOPlugin, quickSEOSetup, } from "./domains/seo/vite/plugin.js";
12
11
  export type { MetaTag, LinkTag, ScriptTag, SEOptions, SEOConfig, RobotsMeta, RobotsDirective, HreflangEntry, PreloadHint, PreconnectOrigin, DnsPrefetchDomain, ArticleMeta, ProductMeta, BreadcrumbItem, OpenGraphImage, SEOValidationResult, } from "./domains/seo/types/index.js";
13
12
  export type { JsonLdTypes, ArticleJsonLd, ProductJsonLd, OrganizationJsonLd, LocalBusinessJsonLd, BreadcrumbJsonLd, FAQJsonLd, WebSiteJsonLd, PersonJsonLd, VideoJsonLd, SchemaType, SchemaGeneratorOptions, } from "./domains/seo/types/schema.js";
package/dist/index.js CHANGED
@@ -15,5 +15,3 @@ export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, va
15
15
  // SSR
16
16
  export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./domains/seo/ssr/renderer.js";
17
17
  export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./domains/seo/ssr/serializer.js";
18
- // Vite Plugin
19
- export { viteSEOPlugin, quickSEOSetup, } from "./domains/seo/vite/plugin.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-seo",
3
- "version": "2.0.12",
3
+ "version": "2.0.15",
4
4
  "description": "Comprehensive SEO solution for React Vite applications with structured data, performance hints, and build-time optimization",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -73,8 +73,8 @@
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/node": "^25.5.0",
76
- "@types/react": "^18.3.2",
77
- "@types/react-dom": "^18.3.0",
76
+ "@types/react": "^19.2.14",
77
+ "@types/react-dom": "^19.2.3",
78
78
  "@typescript-eslint/eslint-plugin": "^8.57.1",
79
79
  "@typescript-eslint/parser": "^8.57.1",
80
80
  "eslint": "^8.57.0",