Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

/dist/js/field.js duplicate code #49

Closed
sblomberg opened this issue Dec 6, 2019 · 1 comment
Closed

/dist/js/field.js duplicate code #49

sblomberg opened this issue Dec 6, 2019 · 1 comment

Comments

@sblomberg
Copy link

/dist/js/field.js has gone from 712kb in this commit https://github.com/froala/nova-froala-field/blob/2c2fef1d0cfe27416776c988df4cdd301bae2068/dist/js/field.js to 2.66mb in the latest update to the file: https://github.com/froala/nova-froala-field/blob/a2126c44721ef67c8156a7c53664241408234ae8/dist/js/field.js This results in the full 2.66mb file being published to the Nova scripts URL at /nova-api/scripts/nova-froala-field and loaded every time a user visits the Nova backend.

One of the problems is that the JS file contains two identical 1.33mb code blocks. To check this, visit the raw file here: https://raw.githubusercontent.com/froala/nova-froala-field/a2126c44721ef67c8156a7c53664241408234ae8/dist/js/field.js, copy any large code block, and do a find on it. You'll see it appear again halfway through the file. Or, download the file, open in a text editor, and turn off line wrapping. Lines 1 and 2 of the file are identical code blocks:

Dec-06-2019 10-52-20

It's possible there's other duplications as well. For example, this code block appears 4 times in the file, and should probably only appear once:

eplace(/\[FROALA\.EDITOR\.NOSCRIPT ([\d]*)\]/gi,function(t,n){return 0<=e.opts.htmlRemoveTags.indexOf("noscript")?"":c[parseInt(n,10)].replace(/&lt;/g,"<").replace(/&gt;/g,">")})).replace(/<img((?:[\w\W]*?)) data-fr-src="/g,'<img$1 src="')}(function(t,n,r){if(e.opts.fullPage){var o=e.html.extractDoctype(r),a=f(e.html.extractNodeAttrs(r,"html"));n=null===n?e.html.extractNode(r,"head")||"<title></title>":n;var i=f(e.html.extractNodeAttrs(r,"head")),s=f(e.html.extractNodeAttrs(r,"body"));return"".concat(o,"<html").concat(a,"><head").concat(i,">").concat(n,"</head><body").concat(s,">").concat(t,"</body></html>")}return t}(o,a,t))}function h(t){var n=e.doc.createElement("DIV");return n.innerText=t,n.textContent}function g(i){for(var s=e.node.contents(i),l=0;l<s.length;l++)s[l].nodeType!==Node.TEXT_NODE&&g(s[l]);!function(i){if("SPAN"===i.tagName&&0<=(i.getAttribute("class")||"").indexOf("fr-marker"))return!1;if("PRE"===i.tagName&&function(e){var t=e.innerHTML;0<=t.indexOf("\n")&&(e.innerHTML=t.replace(/\n/g,"<br>"))}(i),i.nodeType===Node.ELEMENT_NODE&&(i.getAttribute("data-fr-src")&&0!==i.getAttribute("data-fr-src").indexOf("blob:")&&i.setAttribute("data-fr-src",e.helpers.sanitizeURL(h(i.getAttribute("data-fr-src")))),i.getAttribute("href")&&i.setAttribute("href",e.helpers.sanitizeURL(h(i.getAttribute("href")))),i.getAttribute("src")&&i.setAttribute("src",e.helpers.sanitizeURL(h(i.getAttribute("src")))),0<=["TABLE","TBODY","TFOOT","TR"].indexOf(i.tagName)&&(i.innerHTML=i.innerHTML.trim())),!e.opts.pasteAllowLocalImages&&i.nodeType===Node.ELEMENT_NODE&&"IMG"===i.tagName&&i.getAttribute("data-fr-src")&&0===i.getAttribute("data-fr-src").indexOf("file://"))return i.parentNode.removeChild(i),!1;if(i.nodeType===Node.ELEMENT_NODE&&t.HTML5Map[i.tagName]&&""===e.node.attributes(i)){var s=t.HTML5Map[i.tagName],l="<".concat(s,">").concat(i.innerHTML,"</").concat(s,">");i.insertAdjacentHTML("beforebegin",l),(i=i.previousSibling).parentNode.removeChild(i.nextSibling)}if(e.opts.htmlAllowComments||i.nodeType!==Node.COMMENT_NODE)if(i.tagName&&i.tagName.match(r))i.parentNode.removeChild(i);else if(i.tagName&&!i.tagName.match(n))"svg"===i.tagName?i.parentNode.removeChild(i):e.browser.safari&&"path"===i.tagName&&i.parentNode&&"svg"===i.parentNode.tagName||(i.outerHTML=i.innerHTML);else{var c=i.attributes;if(c)for(var f=c.length-1;0<=f;f--){var p=c[f],u=p.nodeName.match(o),g=null;"style"===p.nodeName&&e.opts.htmlAllowedStyleProps.length&&(g=p.value.match(a)),u&&g?p.value=d(g.join(";")):u&&("style"!==p.nodeName||g)||i.removeAttribute(p.nodeName)}}else 0!==i.data.indexOf("[FROALA.EDITOR")&&i.parentNode.removeChild(i)}(i)}return{_init:function(){e.opts.fullPage&&i.merge(e.opts.htmlAllowedTags,["head","title","style","link","base","body","html","meta"])},html:function(t,s,l,c){void 0===s&&(s=[]),void 0===l&&(l=[]),void 0===c&&(c=!1);var d,f=i.merge([],e.opts.htmlAllowedTags);for(d=0;d<s.length;d++)0<=f.indexOf(s[d])&&f

Trimming /dist/js/field.js back down to a reasonable size by removing duplicate code would help speed up our Nova backend. Thanks!

@slavarazum
Copy link
Collaborator

Thanks, fixed in 3.2.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants