Okay, it's a bit more complicated, but still doable.
Here's my solution, that works.

So the spacer (the red thing) is rezising so the footer is always pushed to the bottom of the last page.

Here the full script:
// Calculate the height of the spacer subform
// Put this into its layout ready event
var oSpacer = this.Spacer, // reference to spacer object
nPage = xfa.layout.absPage(oSpacer), // page number, where spacer is currently present. This is the target page.
nSpanPage, // Page number where span starts
oContents = xfa.layout.pageContent(nPage, "subform"), // reference to all subforms on the target page.
aRelevantContents = ["Header", "Contents", "Footer"], // names of the relevant ones
oContentAreaH = Math.round( xfa.layout.h(xfa.layout.pageContent(nPage, "contentArea").item(0), "mm") * 100) / 100, // height of the content area of the target page
oContentH, oContentsH = 0, i, oNode, // variables
nSpacerH = 0.0001; // defaul spacer height
// Check all relevant subforms
for (i = 0; i < oContents.length; i += 1) {
oNode = oContents.item(i); // reference
// if references subform is in the list of the relevants
if (aRelevantContents.some(function (name) {return name === oNode.name;}) ) {
// check if it spans multiple pages, check where it starts and which index is has on the target page. Then get it's height
if (xfa.layout.absPageSpan(oContents.item(i)) > 1) {
nSpanPage = nPage - xfa.layout.absPage(oContents.item(i));
oContentH = Math.round(xfa.layout.h(oContents.item(i), "mm", nSpanPage) * 100) / 100;
// if it doesn't spans pages, get just it's height
} else {
oContentH = Math.round(xfa.layout.h(oContents.item(i), "mm") * 100) / 100;
}
// summarize all heights
oContentsH += oContentH;
}
}
// calculate the height the spacer needs on the target page
nSpacerH += (oContentAreaH - oContentsH);
// set the spacer height
oSpacer.h = nSpacerH + "mm";
// rerender the form
xfa.layout.relayout();
If this helps, mark this as correct answer.