Loading sitewide Javascript files

Hi, I'm developing a large site (around 300+ pages), most of these pages make use of a javascript file which I have organised in the assets folder.

The problem I have is that every page calls to load up every javascript file. For example, my home page uses a couple of javascript files, but the html calls to load every javascript file used on the whole site - up to 300! which has adverse effect on load times.

I know I could amalgamate all javascript files into one large one, but I'd rather not do this as it's far easier to edit them as single files allocated to single pages - they will get edited on a regular basis.

I guess what I'm asking is, can something be done to only load the javascript files that are used on the current page?

Thanks ion advance

1 Like

+1 on this and CSS, CDN's etc. as well. We've asked for this for quite some time now, I do hope it's in the works in one of the upcoming updates soon.

Removing them via script, for people like me that don't really know how to use the export script setup, isn't really an option. And obviously removing them after export would be rediculously tedious work after ever export.

Would really be nice if only the files for the page itself were linked and nothing more. I thought I had read something quite a while back on it in a discussion about this very thing that they added it to their list possibly with a checkbox thing or way to select which files to include on each page. Guess we'll see.

How about adding the specific javascript to the page using the custom code component?

That works yes, but it's a work around, and we shouldn't have to do that :)

That's because you really should be loading a single JS/CSS file so that browser caching works the way it was meant too.

Saj saj.bss.design

I can guarantee you that I will probably "never" have a single JS and CSS file, working that way is pretty much impossible and it's much easier to deal with things when you know exactly where to find them. Not to mention that every time I've tried using the feature in BSS that combines them and minimizes etc. it breaks the site completely. I'll stay with what I'm comfortable with, and I definitely shouldn't be penalized for that. :)

I can combine all my javascript files using a batch command line, but I'd rather not.

I have everything structures in folders within the assets folder making it easy to locate which javascript file I need to update regularly.

Surely this could be implemented?

+1 for this if I'm understanding it correctly.

Current problem: All JS files included in a project get loaded on every page. Is that correct?

Feature Request: Specify per page, which JS files to use.

2 Likes

+1, this is definitely something that would be useful to me.

The only issue I can see this creating is the inability to minify all the JavaScript into a single file when exporting. I however don't mind losing this feature, as minifying the individual files should still be better.

As for browser caching, you could also generate a minified file per each page (minding duplicates) to minimize the number of files. I would reasonably assume that they're cached by individual pages anyway, not once for the entire domain.

I currently have exactly the same problem, this will not be, it would be great then I could elaborate a complete website Bootstrap Studio.

You can set what pages js and css are visible on

In the design tab, right click on your file and choose Visibility

You can then choose what pages to show/not show

image

4 Likes

And boy have things changed since I posted in this thread. I now use SASS and have one (sometimes a few max) CSS files now instead of a dozen lol. Even this old fart learns new tricks :stuck_out_tongue:

Personally I still use multiple css/sass files and just let them get compiled into one file on export. I find it a lot easier for development, eg. I know the styes for a hero div are located in hero.css, no need to scroll through a long file looking for the correct class.

1 Like

Ewww I would never do that either lol. I use one main css file that at least a dozen or 2 sass files are forwarded to so I can still work organized and on export or publish the sass files are all combined to one file. Works pretty slick for me so far. BSS just really makes it easy since it has a built in compiler for them. :slight_smile:

Don’t know why, your Ewww reminded me of this:

Phoebe Ew GIF - Phoebe Ew Disgusted - Discover & Share GIFs

BSS really does makes everything easy, I was talking to a local competitor a few evenings ago, he was saying how he hates doing website, with all the responsive testing etc. I was tempted to tell him about BSS, but, well, he is the competition. I can’t give all my secrets away :wink:

Hahaha I probably look like that sometimes!

Same here, I keep my tools to myself. After all I took a lot of time to find them. Competition can do the same. :stuck_out_tongue_winking_eye:

That’s my preferred workflow as well. I guess I just haven’t found a compelling enough reason to dive into Sass yet.

Ewww always reminds me of this…

image