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

How to load the pdf scripts and packages deferred #113

Open
razfazz opened this issue Mar 19, 2023 · 0 comments
Open

How to load the pdf scripts and packages deferred #113

razfazz opened this issue Mar 19, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@razfazz
Copy link

razfazz commented Mar 19, 2023

I was able to load the flutter_pdf_render deferred by using

import 'package:pdf_render/pdf_render_widgets.dart' deferred as pdf;

But the main problem which delays the initial load time is the section inside the index.html

<script
        src="https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.js"
        type="text/javascript"
></script>
<script type="text/javascript">
  pdfjsLib.GlobalWorkerOptions.workerSrc =
    "https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js";
  pdfRenderOptions = {
    // where cmaps are downloaded from
    cMapUrl: "https://cdn.jsdelivr.net/npm/[email protected]/cmaps/",
    // The cmaps are compressed in the case
    cMapPacked: true,
    // any other options for pdfjsLib.getDocument.
    // params: {}
  };
</script>

Is it possible to load the javascript files also async from dart?

Similar to the following template section

import 'dart:async';
import 'dart:html';

Future<void> loadJavascriptFile() async {
  // Create a ScriptElement
  var jsScript = new ScriptElement();
  jsScript.src = 'path/to/javascript/file.js';

  // Wait for the load event to complete
  await jsScript.onLoad.first;

  // Call a function from the loaded JavaScript file
  context['myFunction'].callMethod('apply', [context, ['arg1', 'arg2']]);
}

void main() async {
  // Call the async function to load the JavaScript file
  await loadJavascriptFile();
}

Thank you for your help in advance and this would be a great achievement to reduce the initial loading time.

@espresso3389 espresso3389 added the enhancement New feature or request label Jun 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants