Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load required scripts and CSS #554

Closed
fredericalpers opened this issue Jun 9, 2023 · 6 comments · Fixed by #610
Closed

Only load required scripts and CSS #554

fredericalpers opened this issue Jun 9, 2023 · 6 comments · Fixed by #610
Labels
QA Issue or Pull request that is in review
Milestone

Comments

@fredericalpers
Copy link
Member

Current state

Currently all JavaScript and CSS files provided by the plugin are always loaded. This worsens the performance of websites. Also it can cause conflicts with Themes, Builders and Plugins used by external customers and their developers/designers. For our projects we use the WordPress Dequeue Function. However this is not always an option for all customers, especially external customers who are working on the website themselves or with other developers/designers.

Investigate

Investigate if and how we can provide and load the Script and CSS files only if necessary.

Desired state

The JavaScript and CSS files should only be loaded when necessary.

@fredericalpers fredericalpers modified the milestones: v4.15, v4.16 Jun 9, 2023
@onOffice-Web-Org onOffice-Web-Org locked and limited conversation to collaborators Jun 12, 2023
@fredericalpers fredericalpers modified the milestones: v4.16, v4.15 Jun 19, 2023
@onOffice-Web-Org onOffice-Web-Org unlocked this conversation Jun 20, 2023
@dai-eastgate
Copy link
Contributor

dai-eastgate commented Jul 27, 2023

Hi @fredericalpers, I checked in the code and see that we have 24 working js files, of which:
image

  • There are 10 files which I can use specific conditions to check and only load required scripts
  • There are 14 files only working in admin which I can't use specific conditions to check, we can add asynchronous loading attribute and load only in the backend
  • There are 8 files only working in front-end which I can't use specific conditions to check, we can add asynchronous loading attribute and load only in the front-end
  • For 2 files which is both working in backend and front-end, we can add asynchronous loading attribute and keep the loading position of those files in as currently.
    Please let us know your opinion about that. Thanks!

@fredericalpers
Copy link
Member Author

@dai-eastgate I will come back to you with an answer as soon as possible

@fredericalpers
Copy link
Member Author

@dai-eastgate Please go ahead and implement the suggested solution. If possible please document the performance improvements before and after.

@dai-eastgate
Copy link
Contributor

@dai-eastgate Please go ahead and implement the suggested solution. If possible please document the performance improvements before and after.

OK, I got it. Thanks!

@dai-eastgate
Copy link
Contributor

@fredericalpers I need 6 days to implement and test because we have changed a lot of files. Thanks

@dai-eastgate
Copy link
Contributor

@fredericalpers
A. After implementation, I have some changes compared to the original as follows:

  1. In the Backend: We still keep the loading position of the files
  2. In the Frontend: I have refactored these files:
  • Estate List: There are 4 files that only load when necessary:
    onoffice-sort-list-selector.js
    onoffice-custom-select.js
    onoffice-form-preview.js
    onoffice-multiselect.js (async)

  • Detail View and Similar estate:
    onoffice_defaultview.js
    slick.js (defer)

  • Contact form, Interest form, Owner form: There are 4 files that only load when necessary:
    onoffice-custom-select.js
    onoffice-multiselect.js (async)
    onoffice-estatetype.js(async)
    onoffice-leadform.js

  • Applicant Search Form: There are 5 files that only load when necessary:
    onoffice-custom-select.js
    onoffice-multiselect.js (async)
    onoffice-estatetype.js(async)
    onoffice-leadform.js
    onoffice-form-preview.js

B. I have added asynchronous properties for 3 files: onoffice-estatetype.js, onoffice-multiselect.js and slick.js. Here are evidence videos of 8 files that I have refactored (The features will be the same as the master branch).

  1. onoffice-sort-list-selector.js: https://files.fm/u/yuwy4v2xf
  2. onoffice-custom-select.js: https://files.fm/u/w5hw556e3
  3. onoffice-form-preview.js: https://files.fm/u/vye4vnk8k
  4. onoffice-multiselect.js: https://files.fm/u/dfkd3unwx
  5. onoffice-estatetype.js: https://files.fm/u/b4gb4jp4p
  6. onoffice-leadform.js: https://files.fm/u/dfs7jygs9
  7. onoffice_defaultview.js: https://files.fm/u/byg7a8b6a
  8. slick.js: https://files.fm/u/yy34t7azq
    Note: I found "onoffice-multiselect.js" file has been removed in version v2.10.0
    => We have refactored the load of that file when necessary. However, to test this file please use the version from v2.9.0 or older.

C. Here are some documents on the performance improvements before and after refactoring the code
image
image

@fredericalpers fredericalpers added QA Issue or Pull request that is in review and removed 2 weeks labels Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA Issue or Pull request that is in review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants