PDA

View Full Version : is it possible to move some of the javascript and css from each html page to files?



Horizon
January 11, 2024, 09:21 AM
I notice on the nova template, there is quite a bit of javascript and css code in each output html page. Is it possible to move the javascript and/or css to a separate file?

For example the 136 lines of javascript that begins with

<script type="text/javascript">
var rlLangDir = 'ltr';
var rlLang = 'en';
var isLogin = false;
var staticDataClass = true;

var lang = new Array();
lang['add_photo'] = 'Add a Picture';
lang['photo'] = 'Picture';
lang['notice_listing_removed_from_favorites'] = 'The listing has been removed from the Favorites.';


And below it the 254 lines of css that begins

/*** GEO LOCATION IN NAVBAR */
.circle #mf-location-selector {
vertical-align: top;
display: inline-block;
}

Or is there a reason that those two for example are better to output in each individual html page instead of called with an src for the js or included in a css file that can be cached/optimized?

I suspect the reason may be simplicity of activating/updating plugins...but I'm wondering if there is or could be a tutorial on optimizing the html output by moving those into optimized/cached files.

I'm trying to get a good report on Google Page Speed Insights mobile.

Rudi
January 11, 2024, 12:43 PM
Hello,

Unfortunately, it's not possible for some js code because it initializes variables given from php at the beginning of the page

and some plugins embed their code directly into the page during the page-building

Horizon
January 12, 2024, 07:48 AM
Regarding the inline js, I wonder how difficult it would be to minify the javascript in the output public html?

Regarding the inline css, I can see how the inline css might make it easier to update plugins, but it sure would be nice to have all those lines in a cached file, plus if I were to want to customize one of those bits, it makes it more difficult if those bits of css are scattered in the plugins rather than in a master style file. I don't think this is something that is super important, but just my wishlist item for the future I guess.

I'm looking for ways to improve the google page speed insights reports, but maybe I'll start a separate thread to see if there are other more beneficial ways to do that.