Title: Exclude javascript from optimization and also fix core web vitals
Last modified: July 25, 2023

---

# Exclude javascript from optimization and also fix core web vitals

 *  Resolved [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/)
 * Hi, I have an issue with autoptimize plugin in one of my websites , as we have
   done the settings and unchecked the Optimize JavaScript Code? under Javascript
   Options, now the core web vitals which was fixed before has failed now. We did
   this settings as we were not getting the google analytics code in the view source
   for users who have not logged in but now we need to fix the core web vitals. 
   The website is done using Timber Framework with WordPress and also is there any
   option to exclude the twig file in which we have all scripts called scripts.twig
    -  This topic was modified 2 years, 10 months ago by [impex23](https://wordpress.org/support/users/impex23/).

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16920343)
 * Hard to say without seeing your site, but generally; in the JS optimization exclusion
   field you can add `wp-content/plugins/pluginname/js/whateverjsfile.js` to exclude
   one specific JS-file or `plugins/pluginname` to exclude the entire plugin or 
   in case of inline JS you can look for a unique parameter name and exclude that.
 * Specifically; AO should leave the default GA code be, but in case you have a 
   non-default implementation you might have to exclude using a parameter name in
   the inline JS or if you’re using a plugin to add GA code, you might have to exclude
   that plugin.
 * Re. twig file; that is a PHP templating framework, AO has no knowledge of that(
   it gets the HTML from WordPress and alters that), you’ll have to exclude based
   on the contents of that template.
 * hope this helps,
    frank
 *  Thread Starter [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16920805)
 * Thanks for the reply, here is the url of my website
   [https://istick.com.au/](https://istick.com.au/)
   can I add /scripts.twig in the JS optimization exclusion field
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16920932)
 * there’s no scripts.twig mentioned in the HTML source anywhere (which makes sense
   as twig is a PHP template), so you’ll have to exclude the JS that is in the template
   impex23 .
 *  Thread Starter [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16920971)
 * Okay thanks for the reply, I will check with it and let you know
 *  Thread Starter [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16926099)
 * I have one more issue with the Lazysizes.min.js not getting cached 
   wp-content/
   plugins/autoptimize/classes/external/js/lazysizes.min.jscan you please suggest
   me how to fix this issue as I am semrush errors for this particular file path
   as uncached or unminified files
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16926219)
 * the only thing I can think of is that lazysizes.min.js comes with a version parameter
   and that “in the old days” this was considered to result in some caching proxies
   not being able to cache the resource (which is not correct). if you go to Settings-
   > Autoptimize -> Extra you can tick the “Remove query strings from static resources”
   and the parameter should be gone 🙂
 *  Thread Starter [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16926373)
 * Okay this setting option is done already – Settings -> Autoptimize -> Extra you
   can tick the “Remove query strings from static resources” but I am not talking
   about the version instead I am asking that this file is not getting cached and
   we are getting error in semrush as Uncached or unminified files, how to fix this
   issue please guide us. Thank you
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16927689)
 * the only thing I can think of are missing expires headers, but that typically
   is done on web-server level, see e.g. [https://webmasters.stackexchange.com/questions/5265/how-do-i-set-expiration-headers-for-css-js-and-images](https://webmasters.stackexchange.com/questions/5265/how-do-i-set-expiration-headers-for-css-js-and-images)
   for info of how to do that for Apache.
 *  Thread Starter [impex23](https://wordpress.org/support/users/impex23/)
 * (@impex23)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16929091)
 * Okay I will check with this, thanks for the quick response

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Exclude javascript from optimization and also fix core web vitals’ is
closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [impex23](https://wordpress.org/support/users/impex23/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/exclude-javascript-from-optimization-and-also-fix-core-web-vitals/#post-16929091)
 * Status: resolved